@@ -12,14 +12,15 @@ import Data.Map as M
1212import Data.Tuple (Tuple (..))
1313import Routing (match )
1414import Routing.Match (Match , list )
15- import Routing.Match.Class (bool , end , int , lit , num , param , params )
15+ import Routing.Match.Class (bool , end , int , lit , num , str , param , params )
1616import Test.Assert (ASSERT , assert' )
1717
1818data FooBar
1919 = Foo Number (M.Map String String )
2020 | Bar Boolean String
2121 | Baz (List Number )
2222 | Quux Int
23+ | Corge String
2324 | End Int
2425
2526derive instance eqFooBar :: Eq FooBar
@@ -29,13 +30,15 @@ instance showFooBar :: Show FooBar where
2930 show (Bar bool str) = " (Bar " <> show bool <> " " <> show str <> " )"
3031 show (Baz lst) = " (Baz " <> show lst <> " )"
3132 show (Quux i) = " (Quux " <> show i <> " )"
33+ show (Corge str) = " (Corge " <> show str <> " )"
3234 show (End i) = " (End " <> show i <> " )"
3335
3436routing :: Match FooBar
3537routing =
3638 Foo <$> (lit " foo" *> num) <*> params
3739 <|> Bar <$> (lit " bar" *> bool) <*> (param " baz" )
3840 <|> Quux <$> (lit " " *> lit " quux" *> int)
41+ <|> Corge <$> (lit " corge" *> str)
3942 -- Order matters here. `list` is greedy, and `end` wont match after it
4043 <|> End <$> (lit " " *> int <* end)
4144 <|> Baz <$> (list num)
@@ -45,6 +48,10 @@ main :: Eff (assert :: ASSERT, console :: CONSOLE) Unit
4548main = do
4649 assertEq (match routing " foo/12/?welp='hi'&b=false" ) (Right (Foo 12.0 (M .fromFoldable [Tuple " welp" " 'hi'" , Tuple " b" " false" ])))
4750 assertEq (match routing " foo/12?welp='hi'&b=false" ) (Right (Foo 12.0 (M .fromFoldable [Tuple " welp" " 'hi'" , Tuple " b" " false" ])))
51+ assertEq (match routing " bar/true?baz=test" ) (Right (Bar true " test" ))
52+ assertEq (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" ) (Right (Bar false " временный файл" ))
53+ assertEq (match routing " corge/test" ) (Right (Corge " test" ))
54+ assertEq (match routing " corge/%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" ) (Right (Corge " временный файл" ))
4855 assertEq (match routing " /quux/42" ) (Right (Quux 42 ))
4956 assertEq (match routing " 123/" ) (Right (Baz (L .fromFoldable [123.0 ])))
5057 assertEq (match routing " /1" ) (Right (End 1 ))
0 commit comments