1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 module test_pop_routes
is test
24 fun test_root_match_only_one_uri
is test
do
25 var r
= new AppRoute("/")
28 assert not r
.match
("/user")
31 fun test_strict_route_match_only_one_uri
is test
do
32 var r
= new AppRoute("/user")
33 assert not r
.match
("/")
34 assert r
.match
("/user")
35 assert r
.match
("/user/")
36 assert not r
.match
("/user/10")
37 assert not r
.match
("/foo")
41 class TestAppParamRoute
44 fun test_param_route_match_good_uri_params_1
is test
do
45 var r
= new AppParamRoute("/:id")
46 assert not r
.match
("/")
47 assert r
.match
("/user")
48 assert r
.match
("/user/")
49 assert not r
.match
("/user/10")
52 fun test_param_route_match_good_uri_params_2
is test
do
53 var r
= new AppParamRoute("/user/:id")
54 assert not r
.match
("/")
55 assert not r
.match
("/user")
56 assert not r
.match
("/user/")
57 assert r
.match
("/user/10")
58 assert r
.match
("/user/10/")
59 assert not r
.match
("/user/10/profile")
62 fun test_param_route_match_good_uri_params_3
is test
do
63 var r
= new AppParamRoute("/user/:id/profile")
64 assert not r
.match
("/")
65 assert not r
.match
("/user")
66 assert not r
.match
("/user/")
67 assert not r
.match
("/user/10")
68 assert not r
.match
("/user/10/")
69 assert r
.match
("/user/10/profile")
70 assert r
.match
("/user/10/profile/")
71 assert not r
.match
("/user/10/profile/settings")
72 assert not r
.match
("/user/10/foo")
75 fun test_param_route_match_good_uri_params_4
is test
do
76 var r
= new AppParamRoute("/:id/:foo")
77 assert not r
.match
("/")
78 assert not r
.match
("/user")
79 assert not r
.match
("/user/")
80 assert r
.match
("/user/10")
81 assert r
.match
("/user/10/")
82 assert not r
.match
("/user/10/10")
85 fun test_param_route_match_good_uri_params_5
is test
do
86 var r
= new AppParamRoute("/user/:id/:foo")
87 assert not r
.match
("/")
88 assert not r
.match
("/user")
89 assert not r
.match
("/foo")
90 assert not r
.match
("/user/10")
91 assert r
.match
("/user/10/10")
92 assert r
.match
("/user/10/10/")
93 assert not r
.match
("/user/10/10/profile")
96 fun test_param_route_match_good_uri_params_6
is test
do
97 var r
= new AppParamRoute("/user/:id/settings/:foo")
98 assert not r
.match
("/")
99 assert not r
.match
("/user")
100 assert not r
.match
("/foo")
101 assert not r
.match
("/user/10")
102 assert not r
.match
("/user/10/10")
103 assert not r
.match
("/user/10/10/")
104 assert not r
.match
("/user/10/10/profile")
105 assert r
.match
("/user/10/settings/profile")
106 assert r
.match
("/user/10/settings/profile/")
107 assert not r
.match
("/user/10/settings/profile/10")
111 class TestRouteMatching
114 fun test_glob_route_match_good_uri_prefix1
is test
do
115 var r
= new AppGlobRoute("/*")
117 assert r
.match
("/user")
118 assert r
.match
("/user/10")
121 fun test_glob_route_match_good_uri_prefix2
is test
do
122 var r
= new AppGlobRoute("/user/*")
123 assert not r
.match
("/")
124 assert r
.match
("/user")
125 assert r
.match
("/user/10")
128 fun test_glob_route_match_good_uri_prefix3
is test
do
129 var r
= new AppGlobRoute("/user*")
130 assert not r
.match
("/")
131 assert r
.match
("/user")
132 assert r
.match
("/user/10")
135 fun test_glob_route_work_with_parameters_1
is test
do
136 var r
= new AppGlobRoute("/:id/*")
137 assert not r
.match
("/")
138 assert r
.match
("/user")
139 assert r
.match
("/user/10")
140 assert r
.match
("/user/10/profile")
143 fun test_glob_route_work_with_parameters_2
is test
do
144 var r
= new AppGlobRoute("/:id*")
145 assert not r
.match
("/")
146 assert r
.match
("/user")
147 assert r
.match
("/user/10")
150 fun test_glob_route_work_with_parameters_3
is test
do
151 var r
= new AppGlobRoute("/user/:id/*")
152 assert not r
.match
("/")
153 assert not r
.match
("/user")
154 assert r
.match
("/user/10")
155 assert r
.match
("/user/10/profile")
158 fun test_glob_route_work_with_parameters_4
is test
do
159 var r
= new AppGlobRoute("/user/:id*")
160 assert not r
.match
("/")
161 assert not r
.match
("/user")
162 assert r
.match
("/user/10")
163 assert r
.match
("/user/10/profile")