Fix ordering for ApiRoute matches.

This commit is contained in:
Dillon Kearns 2022-02-07 08:59:59 -08:00
parent 4e755be53e
commit a39c53de8b
2 changed files with 34 additions and 0 deletions

View File

@ -66,6 +66,7 @@ pathToMatches path (ApiRouteBuilder _ pattern _ _ _) =
path
|> List.concatMap .submatches
|> List.filterMap identity
|> List.reverse
{-| -}
@ -88,6 +89,7 @@ tryMatch path (ApiRouteBuilder _ pattern handler _ _) =
path
|> List.concatMap .submatches
|> List.filterMap identity
|> List.reverse
in
handler matches
|> Just

View File

@ -76,6 +76,38 @@ all =
[ "users/100.json"
, "users/101.json"
]
, test "matches with two dynamic segments" <|
\() ->
succeed
(\author name ->
author ++ " - " ++ name
)
|> literal "package"
|> slash
|> capture
|> slash
|> capture
|> tryMatch "package/dillonkearns/elm-pages"
|> Expect.equal (Just "dillonkearns - elm-pages")
, test "routes with two dynamic segments" <|
\() ->
succeed
(\author name ->
author ++ " - " ++ name
)
|> literal "package"
|> slash
|> capture
|> slash
|> capture
|> withRoutes
(\constructor ->
[ constructor "dillonkearns" "elm-pages"
]
)
|> Expect.equal
[ "package/dillonkearns/elm-pages"
]
, describe "toPattern"
[ test "no dynamic segments" <|
\() ->