@@ -33,6 +33,28 @@ func TestRouterRootMatch(t *testing.T) {
33
33
}
34
34
}
35
35
36
+ func TestRouterRootCatchAll (t * testing.T ) {
37
+ // Create empty handler
38
+ h := new (Handler )
39
+
40
+ // Create empty context
41
+ c := new (Context )
42
+ c .Params = url.Values {}
43
+
44
+ // Create route
45
+ r := Route ("/*" , h )
46
+
47
+ // Matching routes
48
+ rs := []string {"/" , "" , "/something" , "/*" , "/something/else/more" }
49
+
50
+ // Check
51
+ for _ , s := range rs {
52
+ if ! r .Match (s , c ) {
53
+ t .Errorf ("'%s' should match against '*'" , s )
54
+ }
55
+ }
56
+ }
57
+
36
58
func TestRouterRootUnmatch (t * testing.T ) {
37
59
// Create empty handler
38
60
h := new (Handler )
@@ -77,6 +99,28 @@ func TestRouter1LevelMatch(t *testing.T) {
77
99
}
78
100
}
79
101
102
+ func TestRouter1LevelCatchAll (t * testing.T ) {
103
+ // Create empty handler
104
+ h := new (Handler )
105
+
106
+ // Create empty context
107
+ c := new (Context )
108
+ c .Params = url.Values {}
109
+
110
+ // Create route
111
+ r := Route ("/level/*" , h )
112
+
113
+ // Matching routes
114
+ rs := []string {"/level/something" , "level/something" , "/level/*" , "/level/something/else/and/more/because/this/matches/all" }
115
+
116
+ // Check
117
+ for _ , s := range rs {
118
+ if ! r .Match (s , c ) {
119
+ t .Errorf ("'%s' should match against '/level/*'" , s )
120
+ }
121
+ }
122
+ }
123
+
80
124
func TestRouter1LevelUnmatch (t * testing.T ) {
81
125
// Create empty handler
82
126
h := new (Handler )
@@ -121,6 +165,50 @@ func TestRouterMultiLevelMatch(t *testing.T) {
121
165
}
122
166
}
123
167
168
+ func TestRouterMultiLevelWildcard (t * testing.T ) {
169
+ // Create empty handler
170
+ h := new (Handler )
171
+
172
+ // Create empty context
173
+ c := new (Context )
174
+ c .Params = url.Values {}
175
+
176
+ // Create route
177
+ r := Route ("/a/b/*/d" , h )
178
+
179
+ // Matching routes
180
+ rs := []string {"/a/b/c/d" , "a/b/c/d" , "/a/b/*/d" , "a/b/something/d" }
181
+
182
+ // Check
183
+ for _ , s := range rs {
184
+ if ! r .Match (s , c ) {
185
+ t .Errorf ("'%s' should match against '/a/b/*/d" , s )
186
+ }
187
+ }
188
+ }
189
+
190
+ func TestRouterMultiLevelCatchAll (t * testing.T ) {
191
+ // Create empty handler
192
+ h := new (Handler )
193
+
194
+ // Create empty context
195
+ c := new (Context )
196
+ c .Params = url.Values {}
197
+
198
+ // Create route
199
+ r := Route ("/a/b/*" , h )
200
+
201
+ // Matching routes
202
+ rs := []string {"/a/b/c" , "a/b/c" , "/a/b/c/d/e" , "a/b/c/d" }
203
+
204
+ // Check
205
+ for _ , s := range rs {
206
+ if ! r .Match (s , c ) {
207
+ t .Errorf ("'%s' should match against '/a/b/*" , s )
208
+ }
209
+ }
210
+ }
211
+
124
212
func TestRouterMultiLevelUnmatch (t * testing.T ) {
125
213
// Create empty handler
126
214
h := new (Handler )
@@ -165,6 +253,28 @@ func TestRouter1LevelParamMatch(t *testing.T) {
165
253
}
166
254
}
167
255
256
+ func TestRouter1LevelParamCatchAll (t * testing.T ) {
257
+ // Create empty handler
258
+ h := new (Handler )
259
+
260
+ // Create empty context
261
+ c := new (Context )
262
+ c .Params = url.Values {}
263
+
264
+ // Create route
265
+ r := Route ("/:param/*" , h )
266
+
267
+ // Matching routes
268
+ rs := []string {"/a" , "a" , "/cafewafewa" , "/:paramStyle" , "/trailer/" , "/something/more/to/catch" }
269
+
270
+ // Check
271
+ for _ , s := range rs {
272
+ if ! r .Match (s , c ) {
273
+ t .Errorf ("'%s' should match against '/:param/*'" , s )
274
+ }
275
+ }
276
+ }
277
+
168
278
func TestRouter1LevelParamUnmatch (t * testing.T ) {
169
279
// Create empty handler
170
280
h := new (Handler )
@@ -209,6 +319,50 @@ func TestRouterMultiLevelParamMatch(t *testing.T) {
209
319
}
210
320
}
211
321
322
+ func TestRouterMultiLevelParamWildcard (t * testing.T ) {
323
+ // Create empty handler
324
+ h := new (Handler )
325
+
326
+ // Create empty context
327
+ c := new (Context )
328
+ c .Params = url.Values {}
329
+
330
+ // Create route
331
+ r := Route ("/a/*/:param" , h )
332
+
333
+ // Matching routes
334
+ rs := []string {"/a/b/c" , "a/b/c" , "/a/b/c/" , "a/b/c/" , "/a/b/:c" , "/a/b/:param" }
335
+
336
+ // Check
337
+ for _ , s := range rs {
338
+ if ! r .Match (s , c ) {
339
+ t .Errorf ("'%s' should match against '/a/*/:param'" , s )
340
+ }
341
+ }
342
+ }
343
+
344
+ func TestRouterMultiLevelParamCatchAll (t * testing.T ) {
345
+ // Create empty handler
346
+ h := new (Handler )
347
+
348
+ // Create empty context
349
+ c := new (Context )
350
+ c .Params = url.Values {}
351
+
352
+ // Create route
353
+ r := Route ("/a/b/:param/*" , h )
354
+
355
+ // Matching routes
356
+ rs := []string {"/a/b/c" , "a/b/c" , "/a/b/c/" , "a/b/c/" , "/a/b/:c" , "/a/b/:param" , "/a/b/c/d/e/f/g" , "/a/b/c/d/:param/*" }
357
+
358
+ // Check
359
+ for _ , s := range rs {
360
+ if ! r .Match (s , c ) {
361
+ t .Errorf ("'%s' should match against '/a/b/:param/*'" , s )
362
+ }
363
+ }
364
+ }
365
+
212
366
func TestRouterMultiLevelParamUnmatch (t * testing.T ) {
213
367
// Create empty handler
214
368
h := new (Handler )
@@ -328,6 +482,29 @@ func TestRouterGroupMatch(t *testing.T) {
328
482
}
329
483
}
330
484
485
+ func TestRouterGroupCatchAll (t * testing.T ) {
486
+ // Create empty handler
487
+ h := new (Handler )
488
+
489
+ // Create empty context
490
+ c := new (Context )
491
+ c .Params = url.Values {}
492
+
493
+ // Create group
494
+ g := RouteGroup ("/v1" )
495
+ g .Add ("/test/*" , h )
496
+
497
+ // Matching routes
498
+ rs := []string {"/v1/test/test" , "/v1/test/:param/" , "/v1/test/this/is/a/wild/card" }
499
+
500
+ // Check
501
+ for _ , s := range rs {
502
+ if ! g .Match (s , c ) {
503
+ t .Errorf ("'%s' should match" , s )
504
+ }
505
+ }
506
+ }
507
+
331
508
func TestRouterGroupNotMatch (t * testing.T ) {
332
509
// Create empty handler
333
510
h := new (Handler )
0 commit comments