@@ -132,7 +132,7 @@ describe('MatcherPatternPathDynamic', () => {
132132 / ^ \/ t e a m s \/ ( [ ^ / ] + ?) \/ b $ / i,
133133 {
134134 // all defaults
135- teamId : { } ,
135+ teamId : [ { } ] ,
136136 } ,
137137 [ 'teams' , 1 , 'b' ]
138138 )
@@ -153,7 +153,7 @@ describe('MatcherPatternPathDynamic', () => {
153153 const pattern = new MatcherPatternPathDynamic (
154154 / ^ \/ t e a m s \/ ( [ ^ / ] + ?) $ / i,
155155 {
156- teamId : { } ,
156+ teamId : [ { } ] ,
157157 } ,
158158 [ 'teams' , 1 ]
159159 )
@@ -165,7 +165,7 @@ describe('MatcherPatternPathDynamic', () => {
165165 const pattern = new MatcherPatternPathDynamic (
166166 / ^ \/ t e a m s (?: \/ ( [ ^ / ] + ?) ) ? \/ b $ / i,
167167 {
168- teamId : { } ,
168+ teamId : [ { } , false , true ] ,
169169 } ,
170170 [ 'teams' , 1 , 'b' ]
171171 )
@@ -180,30 +180,30 @@ describe('MatcherPatternPathDynamic', () => {
180180 expect ( pattern . build ( { teamId : '' } ) ) . toBe ( '/teams/b' )
181181 } )
182182
183- it . todo ( 'optional param in the end' , ( ) => {
183+ it ( 'optional param in the end' , ( ) => {
184184 const pattern = new MatcherPatternPathDynamic (
185- / ^ \/ t e a m s (?: \/ ( [ ^ / ] + ?) ) ? \/ b $ / i,
185+ / ^ \/ t e a m s (?: \/ ( [ ^ / ] + ?) ) ? $ / i,
186186 {
187- teamId : { } ,
187+ teamId : [ { } , false , true ] ,
188188 } ,
189- [ 'teams' , 1 , 'b' ]
189+ [ 'teams' , 1 ]
190190 )
191191
192- expect ( pattern . match ( '/teams/b' ) ) . toEqual ( { teamId : null } )
193- expect ( pattern . match ( '/teams/123/b' ) ) . toEqual ( { teamId : '123' } )
192+ expect ( pattern . match ( '/teams' ) ) . toEqual ( { teamId : null } )
193+ expect ( ( ) => pattern . match ( '/teams/' ) ) . toThrow ( )
194+ expect ( pattern . match ( '/teams/123' ) ) . toEqual ( { teamId : '123' } )
194195 expect ( ( ) => pattern . match ( '/teams/123/c' ) ) . toThrow ( )
195- expect ( ( ) => pattern . match ( '/teams/123/b/c' ) ) . toThrow ( )
196196 expect ( ( ) => pattern . match ( '/teams//b' ) ) . toThrow ( )
197- expect ( pattern . build ( { teamId : '123' } ) ) . toBe ( '/teams/123/b ' )
198- expect ( pattern . build ( { teamId : null } ) ) . toBe ( '/teams/b ' )
199- expect ( pattern . build ( { teamId : '' } ) ) . toBe ( '/teams/b ' )
197+ expect ( pattern . build ( { teamId : '123' } ) ) . toBe ( '/teams/123' )
198+ expect ( pattern . build ( { teamId : null } ) ) . toBe ( '/teams' )
199+ expect ( pattern . build ( { teamId : '' } ) ) . toBe ( '/teams' )
200200 } )
201201
202202 it ( 'repeatable param' , ( ) => {
203203 const pattern = new MatcherPatternPathDynamic (
204204 / ^ \/ t e a m s \/ ( .+ ?) \/ b $ / i,
205205 {
206- teamId : { repeat : true } ,
206+ teamId : [ { } , true ] ,
207207 } ,
208208 [ 'teams' , 1 , 'b' ]
209209 )
@@ -218,6 +218,25 @@ describe('MatcherPatternPathDynamic', () => {
218218 expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456/b' )
219219 } )
220220
221+ it ( 'repeatable param in the end' , ( ) => {
222+ const pattern = new MatcherPatternPathDynamic (
223+ / ^ \/ t e a m s \/ ( .+ ?) $ / i,
224+ {
225+ teamId : [ { } , true ] ,
226+ } ,
227+ [ 'teams' , 1 ]
228+ )
229+
230+ expect ( pattern . match ( '/teams/123' ) ) . toEqual ( { teamId : [ '123' ] } )
231+ expect ( pattern . match ( '/teams/123/456' ) ) . toEqual ( { teamId : [ '123' , '456' ] } )
232+ expect ( ( ) => pattern . match ( '/teams' ) ) . toThrow ( )
233+ expect ( ( ) => pattern . match ( '/teams/' ) ) . toThrow ( )
234+ expect ( ( ) => pattern . match ( '/teams/123/' ) ) . toThrow ( )
235+ expect ( pattern . build ( { teamId : [ '123' ] } ) ) . toBe ( '/teams/123' )
236+ expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456' )
237+ expect ( ( ) => pattern . build ( { teamId : [ ] } ) ) . toThrow ( )
238+ } )
239+
221240 it . todo ( 'catch all route' , ( ) => {
222241 // const pattern = new MatcherPatternPathDynamic(
223242 } )
@@ -226,9 +245,10 @@ describe('MatcherPatternPathDynamic', () => {
226245 const pattern = new MatcherPatternPathDynamic (
227246 / ^ \/ t e a m s \/ ( .* ) $ / i,
228247 {
229- pathMatch : { } ,
248+ pathMatch : [ { } ] ,
230249 } ,
231- [ 'teams' , 0 ]
250+ [ 'teams' , 0 ] ,
251+ null
232252 )
233253 expect ( pattern . match ( '/teams/' ) ) . toEqual ( { pathMatch : '' } )
234254 expect ( pattern . match ( '/teams/123/b' ) ) . toEqual ( { pathMatch : '123/b' } )
@@ -245,7 +265,7 @@ describe('MatcherPatternPathDynamic', () => {
245265 const pattern = new MatcherPatternPathDynamic (
246266 / ^ \/ t e a m s (?: \/ ( .+ ?) ) ? \/ b $ / i,
247267 {
248- teamId : { repeat : true } ,
268+ teamId : [ { } , true , true ] ,
249269 } ,
250270 [ 'teams' , 1 , 'b' ]
251271 )
@@ -268,8 +288,8 @@ describe('MatcherPatternPathDynamic', () => {
268288 const pattern = new MatcherPatternPathDynamic (
269289 / ^ \/ t e a m s \/ ( [ ^ / ] + ?) \/ ( [ ^ / ] + ?) $ / i,
270290 {
271- teamId : { } ,
272- otherId : { } ,
291+ teamId : [ { } ] ,
292+ otherId : [ { } ] ,
273293 } ,
274294 [ 'teams' , 1 , 1 ]
275295 )
@@ -290,8 +310,8 @@ describe('MatcherPatternPathDynamic', () => {
290310 const pattern = new MatcherPatternPathDynamic (
291311 / ^ \/ t e a m s \/ ( [ ^ / ] + ?) - b - ( [ ^ / ] + ?) $ / i,
292312 {
293- teamId : { } ,
294- otherId : { } ,
313+ teamId : [ { } ] ,
314+ otherId : [ { } ] ,
295315 } ,
296316 [ 'teams' , [ 1 , '-b-' , 1 ] ]
297317 )
@@ -312,9 +332,10 @@ describe('MatcherPatternPathDynamic', () => {
312332 const pattern = new MatcherPatternPathDynamic (
313333 / ^ \/ t e a m s \/ ( [ ^ / ] + ?) \/ $ / i,
314334 {
315- teamId : { } ,
335+ teamId : [ { } ] ,
316336 } ,
317- [ 'teams' , [ 1 , '/' ] ]
337+ [ 'teams' , 1 ] ,
338+ true
318339 )
319340
320341 expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( {
@@ -326,10 +347,11 @@ describe('MatcherPatternPathDynamic', () => {
326347 expect ( pattern . build ( { teamId : '123' } ) ) . toBe ( '/teams/123/' )
327348 } )
328349
329- it ( 'can have a trailing slash after a static segment' , ( ) => {
350+ it . todo ( 'can have a trailing slash after a static segment' , ( ) => {
330351 const pattern = new MatcherPatternPathDynamic ( / ^ \/ t e a m s \/ b \/ $ / i, { } , [
331352 'teams' ,
332- [ 'b' , '/' ] ,
353+ 'b' ,
354+ [ '/' ] ,
333355 ] )
334356
335357 expect ( pattern . match ( '/teams/b/' ) ) . toEqual ( { } )
@@ -343,9 +365,10 @@ describe('MatcherPatternPathDynamic', () => {
343365 const pattern = new MatcherPatternPathDynamic (
344366 / ^ \/ t e a m s \/ ( .+ ?) \/ $ / ,
345367 {
346- teamId : { repeat : true } ,
368+ teamId : [ { } , true ] ,
347369 } ,
348- [ 'teams' , [ 1 , '/' ] ]
370+ [ 'teams' , 1 ] ,
371+ true
349372 )
350373
351374 expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( { teamId : [ '123' ] } )
@@ -359,13 +382,14 @@ describe('MatcherPatternPathDynamic', () => {
359382 expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456/' )
360383 } )
361384
362- it . todo ( 'can have a trailing slash after optional repeatable param' , ( ) => {
385+ it ( 'can have a trailing slash after optional repeatable param' , ( ) => {
363386 const pattern = new MatcherPatternPathDynamic (
364387 / ^ \/ t e a m s (?: \/ ( .+ ?) ) ? \/ $ / ,
365388 {
366- teamId : { repeat : true } ,
389+ teamId : [ { } , true , true ] ,
367390 } ,
368- [ 'teams' , [ 1 , '/' ] ]
391+ [ 'teams' , 1 ] ,
392+ true
369393 )
370394
371395 expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( { teamId : [ '123' ] } )
0 commit comments