@@ -4,46 +4,46 @@ import * as assert from 'uvu/assert';
44import { exec } from '../../src/router.js' ;
55
66function execPath ( path , pattern , opts ) {
7- return exec ( path , pattern , { path, query : { } , params : { } , ...( opts || { } ) } ) ;
7+ return exec ( path , pattern , { path, searchParams : { } , pathParams : { } , ...( opts || { } ) } ) ;
88}
99
1010test ( 'Base route' , ( ) => {
1111 const accurateResult = execPath ( '/' , '/' ) ;
12- assert . equal ( accurateResult , { path : '/' , params : { } , query : { } } ) ;
12+ assert . equal ( accurateResult , { path : '/' , pathParams : { } , searchParams : { } } ) ;
1313
1414 const inaccurateResult = execPath ( '/user/1' , '/' ) ;
1515 assert . equal ( inaccurateResult , undefined ) ;
1616} ) ;
1717
1818test ( 'Param route' , ( ) => {
1919 const accurateResult = execPath ( '/user/2' , '/user/:id' ) ;
20- assert . equal ( accurateResult , { path : '/user/2' , params : { id : '2' } , id : '2' , query : { } } ) ;
20+ assert . equal ( accurateResult , { path : '/user/2' , pathParams : { id : '2' } , id : '2' , searchParams : { } } ) ;
2121
2222 const inaccurateResult = execPath ( '/' , '/user/:id' ) ;
2323 assert . equal ( inaccurateResult , undefined ) ;
2424} ) ;
2525
2626test ( 'Param rest segment' , ( ) => {
2727 const accurateResult = execPath ( '/user/foo' , '/user/*' ) ;
28- assert . equal ( accurateResult , { path : '/user/foo' , params : { } , query : { } , rest : '/foo' } ) ;
28+ assert . equal ( accurateResult , { path : '/user/foo' , pathParams : { } , searchParams : { } , rest : '/foo' } ) ;
2929
3030 const accurateResult2 = execPath ( '/user/foo/bar/baz' , '/user/*' ) ;
31- assert . equal ( accurateResult2 , { path : '/user/foo/bar/baz' , params : { } , query : { } , rest : '/foo/bar/baz' } ) ;
31+ assert . equal ( accurateResult2 , { path : '/user/foo/bar/baz' , pathParams : { } , searchParams : { } , rest : '/foo/bar/baz' } ) ;
3232
3333 const inaccurateResult = execPath ( '/user' , '/user/*' ) ;
3434 assert . equal ( inaccurateResult , undefined ) ;
3535} ) ;
3636
3737test ( 'Param route with rest segment' , ( ) => {
3838 const accurateResult = execPath ( '/user/2/foo' , '/user/:id/*' ) ;
39- assert . equal ( accurateResult , { path : '/user/2/foo' , params : { id : '2' } , id : '2' , query : { } , rest : '/foo' } ) ;
39+ assert . equal ( accurateResult , { path : '/user/2/foo' , pathParams : { id : '2' } , id : '2' , searchParams : { } , rest : '/foo' } ) ;
4040
4141 const accurateResult2 = execPath ( '/user/2/foo/bar/bob' , '/user/:id/*' ) ;
4242 assert . equal ( accurateResult2 , {
4343 path : '/user/2/foo/bar/bob' ,
44- params : { id : '2' } ,
44+ pathParams : { id : '2' } ,
4545 id : '2' ,
46- query : { } ,
46+ searchParams : { } ,
4747 rest : '/foo/bar/bob'
4848 } ) ;
4949
@@ -53,30 +53,30 @@ test('Param route with rest segment', () => {
5353
5454test ( 'Optional param route' , ( ) => {
5555 const accurateResult = execPath ( '/user' , '/user/:id?' ) ;
56- assert . equal ( accurateResult , { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
56+ assert . equal ( accurateResult , { path : '/user' , pathParams : { id : undefined } , id : undefined , searchParams : { } } ) ;
5757
5858 const inaccurateResult = execPath ( '/' , '/user/:id?' ) ;
5959 assert . equal ( inaccurateResult , undefined ) ;
6060} ) ;
6161
6262test ( 'Optional rest param route "/:x*"' , ( ) => {
6363 const matchedResult = execPath ( '/user' , '/user/:id*' ) ;
64- assert . equal ( matchedResult , { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
64+ assert . equal ( matchedResult , { path : '/user' , pathParams : { id : undefined } , id : undefined , searchParams : { } } ) ;
6565
6666 const matchedResultWithSlash = execPath ( '/user/foo/bar' , '/user/:id*' ) ;
6767 assert . equal ( matchedResultWithSlash , {
6868 path : '/user/foo/bar' ,
69- params : { id : 'foo/bar' } ,
69+ pathParams : { id : 'foo/bar' } ,
7070 id : 'foo/bar' ,
71- query : { }
71+ searchParams : { }
7272 } ) ;
7373
7474 const emptyResult = execPath ( '/user' , '/user/:id*' ) ;
7575 assert . equal ( emptyResult , {
7676 path : '/user' ,
77- params : { id : undefined } ,
77+ pathParams : { id : undefined } ,
7878 id : undefined ,
79- query : { }
79+ searchParams : { }
8080 } ) ;
8181
8282 const inaccurateResult = execPath ( '/' , '/user/:id*' ) ;
@@ -85,14 +85,14 @@ test('Optional rest param route "/:x*"', () => {
8585
8686test ( 'Rest param route "/:x+"' , ( ) => {
8787 const matchedResult = execPath ( '/user/foo' , '/user/:id+' ) ;
88- assert . equal ( matchedResult , { path : '/user/foo' , params : { id : 'foo' } , id : 'foo' , query : { } } ) ;
88+ assert . equal ( matchedResult , { path : '/user/foo' , pathParams : { id : 'foo' } , id : 'foo' , searchParams : { } } ) ;
8989
9090 const matchedResultWithSlash = execPath ( '/user/foo/bar' , '/user/:id+' ) ;
9191 assert . equal ( matchedResultWithSlash , {
9292 path : '/user/foo/bar' ,
93- params : { id : 'foo/bar' } ,
93+ pathParams : { id : 'foo/bar' } ,
9494 id : 'foo/bar' ,
95- query : { }
95+ searchParams : { }
9696 } ) ;
9797
9898 const emptyResult = execPath ( '/user' , '/user/:id+' ) ;
@@ -106,22 +106,22 @@ test('Handles leading/trailing slashes', () => {
106106 const result = execPath ( '/about-late/_SEGMENT1_/_SEGMENT2_/' , '/about-late/:seg1/:seg2/' ) ;
107107 assert . equal ( result , {
108108 path : '/about-late/_SEGMENT1_/_SEGMENT2_/' ,
109- params : {
109+ pathParams : {
110110 seg1 : '_SEGMENT1_' ,
111111 seg2 : '_SEGMENT2_'
112112 } ,
113113 seg1 : '_SEGMENT1_' ,
114114 seg2 : '_SEGMENT2_' ,
115- query : { }
115+ searchParams : { }
116116 } ) ;
117117} ) ;
118118
119119test ( 'should not overwrite existing properties' , ( ) => {
120- const result = execPath ( '/foo/bar' , '/:path/:query ' , { path : '/custom-path' } ) ;
120+ const result = execPath ( '/foo/bar' , '/:path/:searchParams ' , { path : '/custom-path' } ) ;
121121 assert . equal ( result , {
122- params : { path : 'foo' , query : 'bar' } ,
122+ pathParams : { path : 'foo' , searchParams : 'bar' } ,
123123 path : '/custom-path' ,
124- query : { }
124+ searchParams : { } ,
125125 } ) ;
126126} ) ;
127127
0 commit comments