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_suite
25 fun test_root_match_only_one_uri
do
26 var r
= new AppRoute("/")
29 assert not r
.match
("/user")
32 fun test_strict_route_match_only_one_uri
do
33 var r
= new AppRoute("/user")
34 assert not r
.match
("/")
35 assert r
.match
("/user")
36 assert r
.match
("/user/")
37 assert not r
.match
("/user/10")
38 assert not r
.match
("/foo")
42 class TestAppParamRoute
45 fun test_param_route_match_good_uri_params_1
do
46 var r
= new AppParamRoute("/:id")
47 assert not r
.match
("/")
48 assert r
.match
("/user")
49 assert r
.match
("/user/")
50 assert not r
.match
("/user/10")
53 fun test_param_route_match_good_uri_params_2
do
54 var r
= new AppParamRoute("/user/:id")
55 assert not r
.match
("/")
56 assert not r
.match
("/user")
57 assert not r
.match
("/user/")
58 assert r
.match
("/user/10")
59 assert r
.match
("/user/10/")
60 assert not r
.match
("/user/10/profile")
63 fun test_param_route_match_good_uri_params_3
do
64 var r
= new AppParamRoute("/user/:id/profile")
65 assert not r
.match
("/")
66 assert not r
.match
("/user")
67 assert not r
.match
("/user/")
68 assert not r
.match
("/user/10")
69 assert not r
.match
("/user/10/")
70 assert r
.match
("/user/10/profile")
71 assert r
.match
("/user/10/profile/")
72 assert not r
.match
("/user/10/profile/settings")
73 assert not r
.match
("/user/10/foo")
76 fun test_param_route_match_good_uri_params_4
do
77 var r
= new AppParamRoute("/:id/:foo")
78 assert not r
.match
("/")
79 assert not r
.match
("/user")
80 assert not r
.match
("/user/")
81 assert r
.match
("/user/10")
82 assert r
.match
("/user/10/")
83 assert not r
.match
("/user/10/10")
86 fun test_param_route_match_good_uri_params_5
do
87 var r
= new AppParamRoute("/user/:id/:foo")
88 assert not r
.match
("/")
89 assert not r
.match
("/user")
90 assert not r
.match
("/foo")
91 assert not r
.match
("/user/10")
92 assert r
.match
("/user/10/10")
93 assert r
.match
("/user/10/10/")
94 assert not r
.match
("/user/10/10/profile")
97 fun test_param_route_match_good_uri_params_6
do
98 var r
= new AppParamRoute("/user/:id/settings/:foo")
99 assert not r
.match
("/")
100 assert not r
.match
("/user")
101 assert not r
.match
("/foo")
102 assert not r
.match
("/user/10")
103 assert not r
.match
("/user/10/10")
104 assert not r
.match
("/user/10/10/")
105 assert not r
.match
("/user/10/10/profile")
106 assert r
.match
("/user/10/settings/profile")
107 assert r
.match
("/user/10/settings/profile/")
108 assert not r
.match
("/user/10/settings/profile/10")
112 class TestRouteMatching
115 fun test_glob_route_match_good_uri_prefix1
do
116 var r
= new AppGlobRoute("/*")
118 assert r
.match
("/user")
119 assert r
.match
("/user/10")
122 fun test_glob_route_match_good_uri_prefix2
do
123 var r
= new AppGlobRoute("/user/*")
124 assert not r
.match
("/")
125 assert r
.match
("/user")
126 assert r
.match
("/user/10")
129 fun test_glob_route_match_good_uri_prefix3
do
130 var r
= new AppGlobRoute("/user*")
131 assert not r
.match
("/")
132 assert r
.match
("/user")
133 assert r
.match
("/user/10")
136 fun test_glob_route_work_with_parameters_1
do
137 var r
= new AppGlobRoute("/:id/*")
138 assert not r
.match
("/")
139 assert r
.match
("/user")
140 assert r
.match
("/user/10")
141 assert r
.match
("/user/10/profile")
144 fun test_glob_route_work_with_parameters_2
do
145 var r
= new AppGlobRoute("/:id*")
146 assert not r
.match
("/")
147 assert r
.match
("/user")
148 assert r
.match
("/user/10")
151 fun test_glob_route_work_with_parameters_3
do
152 var r
= new AppGlobRoute("/user/:id/*")
153 assert not r
.match
("/")
154 assert not r
.match
("/user")
155 assert r
.match
("/user/10")
156 assert r
.match
("/user/10/profile")
159 fun test_glob_route_work_with_parameters_4
do
160 var r
= new AppGlobRoute("/user/:id*")
161 assert not r
.match
("/")
162 assert not r
.match
("/user")
163 assert r
.match
("/user/10")
164 assert r
.match
("/user/10/profile")