@@ -284,5 +284,94 @@ describe('parser', function () {
284284 expect ( parser . parse ( 1234 ) ) . to . deep . include ( defaultObject ) ;
285285 expect ( parser . parse ( { } ) ) . to . deep . include ( defaultObject ) ;
286286 } ) ;
287+
288+ describe ( 'with partial segments' , function ( ) {
289+ function testPartials ( fixtures ) {
290+ fixtures . forEach ( ( [ test , result ] ) => {
291+ expect ( parser . parse ( test ) , `"${ test } "` ) . to . deep . include ( {
292+ ...defaultObject ,
293+ ...result
294+ } ) ;
295+ } ) ;
296+ }
297+
298+ it ( 'should detect partial `url.hash`' , function ( ) {
299+ testPartials ( [
300+ [ '#' , { hash : '' } ] ,
301+ [ '#foo' , { hash : 'foo' } ] ,
302+ [ '#foo#bar' , { hash : 'foo#bar' } ]
303+ ] ) ;
304+ } ) ;
305+
306+ it ( 'should detect partial `url.query`' , function ( ) {
307+ testPartials ( [
308+ [ '?' , { query : [ '' ] } ] ,
309+ [ '??' , { query : [ '?' ] } ] ,
310+ [ '?foo' , { query : [ 'foo' ] } ] ,
311+ [ '?foo=bar' , { query : [ 'foo=bar' ] } ] ,
312+ [ '?foo&bar' , { query : [ 'foo' , 'bar' ] } ] ,
313+ [ '?foo&bar?baz' , { query : [ 'foo' , 'bar?baz' ] } ]
314+ ] ) ;
315+ } ) ;
316+
317+ it ( 'should detect partial `url.protocol`' , function ( ) {
318+ testPartials ( [
319+ [ '://' , { protocol : '' } ] ,
320+ [ ':\\\\' , { protocol : '' } ] ,
321+ [ 'http://' , { protocol : 'http' } ] ,
322+ [ 'file://' , { protocol : 'file' } ] ,
323+ [ 'http:\\\\' , { protocol : 'http' } ] ,
324+ [ 'https://///' , { protocol : 'https' } ] ,
325+ [ 'https:\\\\\\\\' , { protocol : 'https' } ] ,
326+ [ 'file:///' , { protocol : 'file' , path : [ '' ] } ] ,
327+ [ 'file://////' , { protocol : 'file' , path : [ '' ] } ]
328+ ] ) ;
329+ } ) ;
330+
331+ it ( 'should detect partial `url.path`' , function ( ) {
332+ testPartials ( [
333+ [ '/' , { path : [ '' ] } ] ,
334+ [ '\\' , { path : [ '' ] } ] ,
335+ [ '/foo' , { path : [ 'foo' ] } ] ,
336+ [ '//foo' , { path : [ '' , 'foo' ] } ] ,
337+ [ '/foo//' , { path : [ 'foo' , '' , '' ] } ] ,
338+ [ '/foo/bar' , { path : [ 'foo' , 'bar' ] } ] ,
339+ [ '\\\\foo/\\' , { path : [ '' , 'foo' , '' , '' ] } ]
340+ ] ) ;
341+ } ) ;
342+
343+ it ( 'should detect partial `url.auth`' , function ( ) {
344+ testPartials ( [
345+ [ '@' , { auth : [ '' ] } ] ,
346+ [ ':@' , { auth : [ '' , '' ] } ] ,
347+ [ 'foo@' , { auth : [ 'foo' ] } ] ,
348+ [ 'foo:@' , { auth : [ 'foo' , '' ] } ] ,
349+ [ ':bar@' , { auth : [ '' , 'bar' ] } ] ,
350+ [ 'foo:bar@' , { auth : [ 'foo' , 'bar' ] } ]
351+ ] ) ;
352+ } ) ;
353+
354+ it ( 'should detect partial `url.port`' , function ( ) {
355+ testPartials ( [
356+ [ ':' , { port : '' } ] ,
357+ [ ':3000' , { port : '3000' } ] ,
358+ [ 'foo:' , { port : '' , host : [ 'foo' ] } ] ,
359+ [ '::3000' , { port : '3000' , host : [ ':' ] } ] ,
360+ [ ':foo:bar' , { port : 'bar' , host : [ ':foo' ] } ]
361+ ] ) ;
362+ } ) ;
363+
364+ it ( 'should detect partial `url.host`' , function ( ) {
365+ testPartials ( [
366+ [ '.' , { host : [ '' , '' ] } ] ,
367+ [ '..' , { host : [ '' , '' , '' ] } ] ,
368+ [ '..foo' , { host : [ '' , '' , 'foo' ] } ] ,
369+ [ 'foo..' , { host : [ 'foo' , '' , '' ] } ] ,
370+ [ 'localhost' , { host : [ 'localhost' ] } ] ,
371+ [ 'local.host' , { host : [ 'local' , 'host' ] } ] ,
372+ [ 'local..host' , { host : [ 'local' , '' , 'host' ] } ]
373+ ] ) ;
374+ } ) ;
375+ } ) ;
287376 } ) ;
288377} ) ;
0 commit comments