@@ -12,14 +12,15 @@ import Data.Map as M
12
12
import Data.Tuple (Tuple (..))
13
13
import Routing (match )
14
14
import 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 )
16
16
import Test.Assert (ASSERT , assert' )
17
17
18
18
data FooBar
19
19
= Foo Number (M.Map String String )
20
20
| Bar Boolean String
21
21
| Baz (List Number )
22
22
| Quux Int
23
+ | Corge String
23
24
| End Int
24
25
25
26
derive instance eqFooBar :: Eq FooBar
@@ -29,13 +30,15 @@ instance showFooBar :: Show FooBar where
29
30
show (Bar bool str) = " (Bar " <> show bool <> " " <> show str <> " )"
30
31
show (Baz lst) = " (Baz " <> show lst <> " )"
31
32
show (Quux i) = " (Quux " <> show i <> " )"
33
+ show (Corge str) = " (Corge " <> show str <> " )"
32
34
show (End i) = " (End " <> show i <> " )"
33
35
34
36
routing :: Match FooBar
35
37
routing =
36
38
Foo <$> (lit " foo" *> num) <*> params
37
39
<|> Bar <$> (lit " bar" *> bool) <*> (param " baz" )
38
40
<|> Quux <$> (lit " " *> lit " quux" *> int)
41
+ <|> Corge <$> (lit " corge" *> str)
39
42
-- Order matters here. `list` is greedy, and `end` wont match after it
40
43
<|> End <$> (lit " " *> int <* end)
41
44
<|> Baz <$> (list num)
@@ -45,6 +48,10 @@ main :: Eff (assert :: ASSERT, console :: CONSOLE) Unit
45
48
main = do
46
49
assertEq (match routing " foo/12/?welp='hi'&b=false" ) (Right (Foo 12.0 (M .fromFoldable [Tuple " welp" " 'hi'" , Tuple " b" " false" ])))
47
50
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 " временный файл" ))
48
55
assertEq (match routing " /quux/42" ) (Right (Quux 42 ))
49
56
assertEq (match routing " 123/" ) (Right (Baz (L .fromFoldable [123.0 ])))
50
57
assertEq (match routing " /1" ) (Right (End 1 ))
0 commit comments