@@ -175,5 +175,103 @@ describe('router', function () {
175175 expect ( route ) . not . toBeNull ( )
176176 expect ( route ?. params ) . toStrictEqual ( { id : '42' , path : 'docs/readme.md' } )
177177 } )
178+
179+ it ( 'matches a route with handler value 0' , function ( { expect } ) {
180+ const router = createMatcher < number > ( )
181+
182+ router . register ( '/zero' , 0 )
183+
184+ const route = router . match ( '/zero' )
185+
186+ expect ( route ) . not . toBeNull ( )
187+ expect ( route ?. handler ) . toBe ( 0 )
188+ } )
189+
190+ it ( 'matches a route with handler value empty string' , function ( { expect } ) {
191+ const router = createMatcher < string > ( )
192+
193+ router . register ( '/empty' , '' )
194+
195+ const route = router . match ( '/empty' )
196+
197+ expect ( route ) . not . toBeNull ( )
198+ expect ( route ?. handler ) . toBe ( '' )
199+ } )
200+
201+ it ( 'matches a route with handler value false' , function ( { expect } ) {
202+ const router = createMatcher < boolean > ( )
203+
204+ router . register ( '/false' , false )
205+
206+ const route = router . match ( '/false' )
207+
208+ expect ( route ) . not . toBeNull ( )
209+ expect ( route ?. handler ) . toBe ( false )
210+ } )
211+
212+ it ( 'matches a wildcard route with handler value 0' , function ( { expect } ) {
213+ const router = createMatcher < number > ( )
214+
215+ router . register ( '/files/*path' , 0 )
216+
217+ const route = router . match ( '/files/readme.md' )
218+
219+ expect ( route ) . not . toBeNull ( )
220+ expect ( route ?. handler ) . toBe ( 0 )
221+ expect ( route ?. params ) . toStrictEqual ( { path : 'readme.md' } )
222+ } )
223+
224+ it ( 'matches root handler' , function ( { expect } ) {
225+ const router = createMatcher < number > ( )
226+
227+ router . register ( '/' , 1 )
228+
229+ const route = router . match ( '/' )
230+
231+ expect ( route ) . not . toBeNull ( )
232+ expect ( route ?. handler ) . toBe ( 1 )
233+ } )
234+ } )
235+
236+ describe ( 'param name conflicts' , function ( ) {
237+ it ( 'throws on conflicting dynamic param names at the same level' , function ( { expect } ) {
238+ const router = createMatcher < number > ( )
239+
240+ router . register ( '/user/:id/profile' , 1 )
241+
242+ expect ( function ( ) {
243+ router . register ( '/user/:name/settings' , 2 )
244+ } ) . toThrow ( 'conflicting dynamic param name' )
245+ } )
246+
247+ it ( 'throws on conflicting wildcard param names at the same level' , function ( { expect } ) {
248+ const router = createMatcher < number > ( )
249+
250+ router . register ( '/files/*path' , 1 )
251+
252+ expect ( function ( ) {
253+ router . register ( '/files/*filepath' , 2 )
254+ } ) . toThrow ( 'conflicting wildcard param name' )
255+ } )
256+
257+ it ( 'allows the same dynamic param name at the same level' , function ( { expect } ) {
258+ const router = createMatcher < number > ( )
259+
260+ router . register ( '/user/:id/profile' , 1 )
261+
262+ expect ( function ( ) {
263+ router . register ( '/user/:id/settings' , 2 )
264+ } ) . not . toThrow ( )
265+ } )
266+
267+ it ( 'allows the same wildcard param name at the same level' , function ( { expect } ) {
268+ const router = createMatcher < number > ( )
269+
270+ router . register ( '/files/*path' , 1 )
271+
272+ expect ( function ( ) {
273+ router . register ( '/other/*path' , 2 )
274+ } ) . not . toThrow ( )
275+ } )
178276 } )
179277} )
0 commit comments