@@ -10,7 +10,7 @@ type Test = [
1010 pathToRegexp . Path ,
1111 pathToRegexp . RegExpOptions & pathToRegexp . ParseOptions ,
1212 pathToRegexp . Token [ ] ,
13- Array < [ string , string [ ] ] > ,
13+ Array < [ string , string [ ] , pathToRegexp . Match ? ] > ,
1414 Array < [ any , string ] | [ any , string , pathToRegexp . PathFunctionOptions ] >
1515]
1616
@@ -30,8 +30,8 @@ var TESTS: Test[] = [
3030 '/'
3131 ] ,
3232 [
33- [ '/' , [ '/' ] ] ,
34- [ '/route' , null ]
33+ [ '/' , [ '/' ] , { path : '/' , index : 0 , params : { } } ] ,
34+ [ '/route' , null , false ]
3535 ] ,
3636 [
3737 [ null , '/' ] ,
@@ -46,10 +46,10 @@ var TESTS: Test[] = [
4646 '/test'
4747 ] ,
4848 [
49- [ '/test' , [ '/test' ] ] ,
50- [ '/route' , null ] ,
51- [ '/test/route' , null ] ,
52- [ '/test/' , [ '/test/' ] ]
49+ [ '/test' , [ '/test' ] , { path : '/test' , index : 0 , params : { } } ] ,
50+ [ '/route' , null , false ] ,
51+ [ '/test/route' , null , false ] ,
52+ [ '/test/' , [ '/test/' ] , { path : '/test/' , index : 0 , params : { } } ]
5353 ] ,
5454 [
5555 [ null , '/test' ] ,
@@ -201,7 +201,7 @@ var TESTS: Test[] = [
201201 }
202202 ] ,
203203 [
204- [ '/route' , [ '/route' , 'route' ] ]
204+ [ '/route' , [ '/route' , 'route' ] , { path : '/route' , index : 0 , params : { test : 'route' } } ]
205205 ] ,
206206 [
207207 [ { } , null ] ,
@@ -734,9 +734,9 @@ var TESTS: Test[] = [
734734 }
735735 ] ,
736736 [
737- [ '/route' , [ '/route' , 'route' ] ] ,
738- [ '/route/nested' , null ] ,
739- [ '/' , [ '/' , undefined ] ] ,
737+ [ '/route' , [ '/route' , 'route' ] , { path : '/route' , index : 0 , params : { test : 'route' } } ] ,
738+ [ '/route/nested' , null , false ] ,
739+ [ '/' , [ '/' , undefined ] , { path : '/' , index : 0 , params : { } } ] ,
740740 [ '//' , null ]
741741 ] ,
742742 [
@@ -885,10 +885,10 @@ var TESTS: Test[] = [
885885 }
886886 ] ,
887887 [
888- [ '/' , null ] ,
889- [ '/route' , [ '/route' , 'route' ] ] ,
890- [ '/some/basic/route' , [ '/some/basic/route' , 'some/basic/route' ] ] ,
891- [ '//' , null ]
888+ [ '/' , null , false ] ,
889+ [ '/route' , [ '/route' , 'route' ] , { path : '/route' , index : 0 , params : { test : [ 'route' ] } } ] ,
890+ [ '/some/basic/route' , [ '/some/basic/route' , 'some/basic/route' ] , { path : '/some/basic/route' , index : 0 , params : { test : [ 'some' , 'basic' , 'route' ] } } ] ,
891+ [ '//' , null , false ]
892892 ] ,
893893 [
894894 [ { } , null ] ,
@@ -988,13 +988,14 @@ var TESTS: Test[] = [
988988 }
989989 ] ,
990990 [
991- [ '/' , [ '/' , undefined ] ] ,
992- [ '//' , null ] ,
993- [ '/route' , [ '/route' , 'route' ] ] ,
994- [ '/some/basic/route' , [ '/some/basic/route' , 'some/basic/route' ] ]
991+ [ '/' , [ '/' , undefined ] , { path : '/' , index : 0 , params : { } } ] ,
992+ [ '//' , null , false ] ,
993+ [ '/route' , [ '/route' , 'route' ] , { path : '/route' , index : 0 , params : { test : [ 'route' ] } } ] ,
994+ [ '/some/basic/route' , [ '/some/basic/route' , 'some/basic/route' ] , { path : '/some/basic/route' , index : 0 , params : { test : [ 'some' , 'basic' , 'route' ] } } ]
995995 ] ,
996996 [
997997 [ { } , '' ] ,
998+ [ { test : [ ] } , '' ] ,
998999 [ { test : 'foobar' } , '/foobar' ] ,
9991000 [ { test : [ 'foo' , 'bar' ] } , '/foo/bar' ]
10001001 ]
@@ -2782,18 +2783,18 @@ describe('path-to-regexp', function () {
27822783 var toPath = pathToRegexp . compile ( path as string , opts )
27832784
27842785 compileCases . forEach ( function ( io ) {
2785- var input = io [ 0 ]
2786- var output = io [ 1 ]
2786+ var params = io [ 0 ]
2787+ var path = io [ 1 ]
27872788 var options = io [ 2 ]
27882789
2789- if ( output != null ) {
2790- it ( 'should compile using ' + util . inspect ( input ) , function ( ) {
2791- expect ( toPath ( input , options ) ) . to . equal ( output )
2790+ if ( path != null ) {
2791+ it ( 'should compile using ' + util . inspect ( params ) , function ( ) {
2792+ expect ( toPath ( params , options ) ) . to . equal ( path )
27922793 } )
27932794 } else {
2794- it ( 'should not compile using ' + util . inspect ( input ) , function ( ) {
2795+ it ( 'should not compile using ' + util . inspect ( params ) , function ( ) {
27952796 expect ( function ( ) {
2796- toPath ( input , options )
2797+ toPath ( params , options )
27972798 } ) . to . throw ( TypeError )
27982799 } )
27992800 }
@@ -2809,13 +2810,22 @@ describe('path-to-regexp', function () {
28092810
28102811 describe ( 'match' + ( opts ? ' using ' + util . inspect ( opts ) : '' ) , function ( ) {
28112812 matchCases . forEach ( function ( io ) {
2812- var input = io [ 0 ]
2813- var output = io [ 1 ]
2814- var message = 'should' + ( output ? ' ' : ' not ' ) + 'match ' + util . inspect ( input )
2813+ var pathname = io [ 0 ]
2814+ var matches = io [ 1 ]
2815+ var params = io [ 2 ]
2816+ var message = 'should' + ( matches ? ' ' : ' not ' ) + 'match ' + util . inspect ( pathname )
28152817
28162818 it ( message , function ( ) {
2817- expect ( exec ( re , input ) ) . to . deep . equal ( output )
2819+ expect ( exec ( re , pathname ) ) . to . deep . equal ( matches )
28182820 } )
2821+
2822+ if ( typeof path === "string" && params !== undefined ) {
2823+ var match = pathToRegexp . match ( path )
2824+
2825+ it ( message + ' params' , function ( ) {
2826+ expect ( match ( pathname ) ) . to . deep . equal ( params )
2827+ } )
2828+ }
28192829 } )
28202830 } )
28212831 } )
0 commit comments