@@ -211,7 +211,7 @@ test('param :: optional :: multiple', () => {
211
211
212
212
test ( 'wildcard' , ( ) => {
213
213
let { keys, pattern } = parse ( '/books/*' ) ;
214
- assert . equal ( keys , [ 'wild ' ] , '~> keys has "wild " value' ) ;
214
+ assert . equal ( keys , [ '* ' ] , '~> keys has "* " value' ) ;
215
215
assert . not . ok ( pattern . test ( '/books' ) , '~> does not match naked base' ) ;
216
216
assert . ok ( pattern . test ( '/books/' ) , '~> does not match naked base w/ trailing slash' ) ;
217
217
assert . ok ( pattern . test ( '/books/narnia' ) , '~> matches definition' ) ;
@@ -224,7 +224,32 @@ test('wildcard', () => {
224
224
225
225
test ( 'wildcard :: root' , ( ) => {
226
226
let { keys, pattern } = parse ( '*' ) ;
227
- assert . equal ( keys , [ 'wild' ] , '~> keys has "wild" value' ) ;
227
+ assert . equal ( keys , [ '*' ] , '~> keys has "*" value' ) ;
228
+ assert . ok ( pattern . test ( '/' ) , '~> matches root path' ) ;
229
+ assert . ok ( pattern . test ( '/narnia' ) , '~> matches definition' ) ;
230
+ assert . ok ( pattern . test ( '/narnia/' ) , '~> matches definition w/ trailing slash' ) ;
231
+ assert . ok ( pattern . test ( '/narnia/reviews' ) , '~> does not match extra bits' ) ;
232
+ assert . not . ok ( pattern . test ( 'narnia' ) , '~> does not match path without lead slash' ) ;
233
+ let [ _ , value ] = pattern . exec ( '/foo/bar/baz' ) ;
234
+ assert . is ( value , 'foo/bar/baz' , '~> executing pattern gives ALL values together' ) ;
235
+ } ) ;
236
+
237
+ test ( 'optional wildcard' , ( ) => {
238
+ let { keys, pattern } = parse ( '/books/*?' ) ;
239
+ assert . equal ( keys , [ '*' ] , '~> keys has "*" value' ) ;
240
+ assert . ok ( pattern . test ( '/books' ) , '~> matches naked base' ) ;
241
+ assert . ok ( pattern . test ( '/books/' ) , '~> matches naked base w/ trailing slash' ) ;
242
+ assert . ok ( pattern . test ( '/books/narnia' ) , '~> matches definition' ) ;
243
+ assert . ok ( pattern . test ( '/books/narnia/' ) , '~> matches definition w/ trailing slash' ) ;
244
+ assert . ok ( pattern . test ( '/books/narnia/reviews' ) , '~> does not match extra bits' ) ;
245
+ assert . not . ok ( pattern . test ( 'books/narnia' ) , '~> does not match path without lead slash' ) ;
246
+ let [ _ , value ] = pattern . exec ( '/books/narnia/reviews' ) ;
247
+ assert . is ( value , 'narnia/reviews' , '~> executing pattern gives ALL values after base' ) ;
248
+ } ) ;
249
+
250
+ test ( 'optional wildcard :: root' , ( ) => {
251
+ let { keys, pattern } = parse ( '*?' ) ;
252
+ assert . equal ( keys , [ '*' ] , '~> keys has "*" value' ) ;
228
253
assert . ok ( pattern . test ( '/' ) , '~> matches root path' ) ;
229
254
assert . ok ( pattern . test ( '/narnia' ) , '~> matches definition' ) ;
230
255
assert . ok ( pattern . test ( '/narnia/' ) , '~> matches definition w/ trailing slash' ) ;
@@ -283,19 +308,19 @@ test('execs', () => {
283
308
284
309
// console.log('/books/*');
285
310
toExec ( '/books/*' , '/books' , false ) ;
286
- toExec ( '/books/*' , '/books/' , { wild :null } ) ;
287
- toExec ( '/books/*' , '/books/world' , { wild :'world' } ) ;
288
- toExec ( '/books/*' , '/books/world/' , { wild :'world/' } ) ;
289
- toExec ( '/books/*' , '/books/world/howdy' , { wild :'world/howdy' } ) ;
290
- toExec ( '/books/*' , '/books/world/howdy/' , { wild :'world/howdy/' } ) ;
311
+ toExec ( '/books/*' , '/books/' , { '*' :null } ) ;
312
+ toExec ( '/books/*' , '/books/world' , { '*' :'world' } ) ;
313
+ toExec ( '/books/*' , '/books/world/' , { '*' :'world/' } ) ;
314
+ toExec ( '/books/*' , '/books/world/howdy' , { '*' :'world/howdy' } ) ;
315
+ toExec ( '/books/*' , '/books/world/howdy/' , { '*' :'world/howdy/' } ) ;
291
316
292
317
// console.log('/books/*?');
293
- toExec ( '/books/*?' , '/books' , { wild :null } ) ;
294
- toExec ( '/books/*?' , '/books/' , { wild :null } ) ;
295
- toExec ( '/books/*?' , '/books/world' , { wild :'world' } ) ;
296
- toExec ( '/books/*?' , '/books/world/' , { wild :'world/' } ) ;
297
- toExec ( '/books/*?' , '/books/world/howdy' , { wild :'world/howdy' } ) ;
298
- toExec ( '/books/*?' , '/books/world/howdy/' , { wild :'world/howdy/' } ) ;
318
+ toExec ( '/books/*?' , '/books' , { '*' :null } ) ;
319
+ toExec ( '/books/*?' , '/books/' , { '*' :null } ) ;
320
+ toExec ( '/books/*?' , '/books/world' , { '*' :'world' } ) ;
321
+ toExec ( '/books/*?' , '/books/world/' , { '*' :'world/' } ) ;
322
+ toExec ( '/books/*?' , '/books/world/howdy' , { '*' :'world/howdy' } ) ;
323
+ toExec ( '/books/*?' , '/books/world/howdy/' , { '*' :'world/howdy/' } ) ;
299
324
} ) ;
300
325
301
326
test ( 'execs :: loose' , ( ) => {
@@ -347,19 +372,19 @@ test('execs :: loose', () => {
347
372
348
373
// console.log('/books/*');
349
374
toLooseExec ( '/books/*' , '/books' , false ) ;
350
- toLooseExec ( '/books/*' , '/books/' , { wild :null } ) ;
351
- toLooseExec ( '/books/*' , '/books/world' , { wild :'world' } ) ;
352
- toLooseExec ( '/books/*' , '/books/world/' , { wild :'world/' } ) ;
353
- toLooseExec ( '/books/*' , '/books/world/howdy' , { wild :'world/howdy' } ) ;
354
- toLooseExec ( '/books/*' , '/books/world/howdy/' , { wild :'world/howdy/' } ) ;
375
+ toLooseExec ( '/books/*' , '/books/' , { '*' :null } ) ;
376
+ toLooseExec ( '/books/*' , '/books/world' , { '*' :'world' } ) ;
377
+ toLooseExec ( '/books/*' , '/books/world/' , { '*' :'world/' } ) ;
378
+ toLooseExec ( '/books/*' , '/books/world/howdy' , { '*' :'world/howdy' } ) ;
379
+ toLooseExec ( '/books/*' , '/books/world/howdy/' , { '*' :'world/howdy/' } ) ;
355
380
356
381
// console.log('/books/*?');
357
- toLooseExec ( '/books/*?' , '/books' , { wild :null } ) ;
358
- toLooseExec ( '/books/*?' , '/books/' , { wild :null } ) ;
359
- toLooseExec ( '/books/*?' , '/books/world' , { wild :'world' } ) ;
360
- toLooseExec ( '/books/*?' , '/books/world/' , { wild :'world/' } ) ;
361
- toLooseExec ( '/books/*?' , '/books/world/howdy' , { wild :'world/howdy' } ) ;
362
- toLooseExec ( '/books/*?' , '/books/world/howdy/' , { wild :'world/howdy/' } ) ;
382
+ toLooseExec ( '/books/*?' , '/books' , { '*' :null } ) ;
383
+ toLooseExec ( '/books/*?' , '/books/' , { '*' :null } ) ;
384
+ toLooseExec ( '/books/*?' , '/books/world' , { '*' :'world' } ) ;
385
+ toLooseExec ( '/books/*?' , '/books/world/' , { '*' :'world/' } ) ;
386
+ toLooseExec ( '/books/*?' , '/books/world/howdy' , { '*' :'world/howdy' } ) ;
387
+ toLooseExec ( '/books/*?' , '/books/world/howdy/' , { '*' :'world/howdy/' } ) ;
363
388
} ) ;
364
389
365
390
test ( '(raw) exec' , ( ) => {
0 commit comments