Skip to content

Commit 12ff339

Browse files
authored
Merge pull request #70 from garyb/param-consume-query
Make `param` remove `Query` once all parameters have been consumed
2 parents 269ace0 + aed07e2 commit 12ff339

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Routing/Match.purs

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ param key = Match \route ->
118118
case M.lookup key map of
119119
Nothing ->
120120
invalid $ free $ KeyNotFound key
121-
Just el ->
122-
pure $ Tuple (Cons (Query <<< M.delete key $ map) rs) el
121+
Just el -> do
122+
let remainingParams = M.delete key map
123+
pure $
124+
if M.isEmpty remainingParams
125+
then Tuple rs el
126+
else Tuple (Cons (Query remainingParams) rs) el
123127
_ ->
124128
invalid $ free ExpectedQuery
125129

test/Test/Main.purs

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ instance showMyRoutes :: Show MyRoutes where show = genericShow
3535
routing :: Match MyRoutes
3636
routing = oneOf
3737
[ Foo <$> (lit "foo" *> num) <*> params
38-
, Bar <$> (lit "bar" *> bool) <*> (param "baz")
38+
, Bar <$> (lit "bar" *> bool) <*> (param "baz") <* end
3939
, Baz <$> (lit "list" *> list num)
4040
, Quux <$> (lit "" *> lit "quux" *> int)
4141
, Corge <$> (lit "corge" *> str)
@@ -57,6 +57,10 @@ main = do
5757
{ actual: match routing "bar/true?baz=test"
5858
, expected: Right (Bar true "test")
5959
}
60+
assertEqual
61+
{ actual: lmap (const unit) (match routing "bar/true?baz=test&oof=true")
62+
, expected: Left unit
63+
}
6064
assertEqual
6165
{ actual: match routing "bar/false?baz=%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9%20%D1%84%D0%B0%D0%B9%D0%BB"
6266
, expected: Right (Bar false "временный файл")

0 commit comments

Comments
 (0)