@@ -322,34 +322,55 @@ describe('picomatch', () => { |
322 | 322 | }); |
323 | 323 | }); |
324 | 324 |
|
325 | | - it('should return parts of the pattern', () => { |
326 | | - // Right now it returns [] |
327 | | - // assertParts('', ['']); |
328 | | - // assertParts('*', ['*']); |
329 | | - // assertParts('.*', ['.*']); |
330 | | - // assertParts('**', ['**']); |
331 | | - // assertParts('foo', ['foo']); |
332 | | - // assertParts('foo*', ['foo*']); |
333 | | - // assertParts('/', ['', '']); |
334 | | - // assertParts('/*', ['', '*']); |
335 | | - // assertParts('./', ['']); |
336 | | - // assertParts('{1..9}', ['{1..9}']); |
337 | | - // assertParts('c!(.)z', ['c!(.)z']); |
338 | | - // assertParts('(b|a).(a)', ['(b|a).(a)']); |
339 | | - // assertParts('+(a|b\\[)*', ['+(a|b\\[)*']); |
340 | | - // assertParts('@(a|b).md', ['@(a|b).md']); |
341 | | - // assertParts('(a/b)', ['(a/b)']); |
342 | | - // assertParts('(a\\b)', ['(a\\b)']); |
343 | | - // assertParts('foo\\[a\\/]', ['foo\\[a\\/]']); |
344 | | - // assertParts('foo[/]bar', ['foo[/]bar']); |
345 | | - // assertParts('/dev\\/@(tcp|udp)\\/*\\/*', ['', '/dev\\/@(tcp|udp)\\/*\\/*']); |
346 | | - |
347 | | - // Right now it returns ['*'] |
348 | | - // assertParts('*/', ['*', '']); |
349 | | - |
350 | | - // Right now it returns ['!(!(bar)', 'baz)'] |
351 | | - // assertParts('!(!(bar)/baz)', ['!(!(bar)/baz)']); |
| 325 | + it('should return a single part for patterns without path separators', () => { |
| 326 | + assertParts('', ['']); |
| 327 | + assertParts('*', ['*']); |
| 328 | + assertParts('.*', ['.*']); |
| 329 | + assertParts('**', ['**']); |
| 330 | + assertParts('foo', ['foo']); |
| 331 | + assertParts('!foo', ['foo']); |
| 332 | + assertParts('foo*', ['foo*']); |
| 333 | + assertParts('{1..9}', ['{1..9}']); |
| 334 | + assertParts('c!(.)z', ['c!(.)z']); |
| 335 | + assertParts('(b|a).(a)', ['(b|a).(a)']); |
| 336 | + assertParts('+(a|b\\[)*', ['+(a|b\\[)*']); |
| 337 | + assertParts('@(a|b).md', ['@(a|b).md']); |
| 338 | + assertParts('(a/b)', ['(a/b)']); |
| 339 | + assertParts('(a\\b)', ['(a\\b)']); |
| 340 | + assertParts('foo\\[a\\/]', ['foo\\[a\\/]']); |
| 341 | + assertParts('foo[/]bar', ['foo[/]bar']); |
| 342 | + }); |
| 343 | + |
| 344 | + it('should preserve leading and trailing empty parts', () => { |
| 345 | + assertParts('/', ['', '']); |
| 346 | + assertParts('/*', ['', '*']); |
| 347 | + assertParts('/a', ['', 'a']); |
| 348 | + assertParts('/a/b', ['', 'a', 'b']); |
| 349 | + assertParts('/a/b/', ['', 'a', 'b', '']); |
| 350 | + assertParts('*/', ['*', '']); |
| 351 | + assertParts('./', ['']); |
| 352 | + }); |
| 353 | + |
| 354 | + it('should return parts when tokens are requested', () => { |
| 355 | + assert.deepStrictEqual(scan('/', { tokens: true }).parts, ['', '']); |
| 356 | + assert.deepStrictEqual(scan('/a/b', { tokens: true }).parts, ['', 'a', 'b']); |
| 357 | + assert.deepStrictEqual(scan('!foo', { tokens: true }).parts, ['foo']); |
| 358 | + assert.deepStrictEqual(scan('./!a/b', { tokens: true }).parts, ['a', 'b']); |
| 359 | + assert.deepStrictEqual(scan('a/b/*/c', { tokens: true }).parts, ['a', 'b', '*', 'c']); |
| 360 | + }); |
| 361 | + |
| 362 | + it('should split only on unnested and unescaped path separators', () => { |
| 363 | + assertParts('/dev\\/@(tcp|udp)\\/*\\/*', ['', 'dev\\/@(tcp|udp)\\/*\\/*']); |
| 364 | + assertParts('!(!(bar)/baz)', ['!(!(bar)/baz)']); |
| 365 | + assertParts('(!(b/a))', ['(!(b/a))']); |
| 366 | + assertParts('a/((b)/c)/d', ['a', '((b)/c)', 'd']); |
| 367 | + assertParts('a/(b\\)/c)/d', ['a', '(b\\)/c)', 'd']); |
| 368 | + assertParts('(a|b)/c', ['(a|b)', 'c']); |
| 369 | + assertParts('./directory/(a|b)/*.js', ['directory', '(a|b)', '*.js']); |
| 370 | + assertParts('a/@(!(b)/c)/*.js', ['a', '@(!(b)/c)', '*.js']); |
| 371 | + }); |
352 | 372 |
|
| 373 | + it('should return parts of the pattern', () => { |
353 | 374 | assertParts('./foo', ['foo']); |
354 | 375 | assertParts('../foo', ['..', 'foo']); |
355 | 376 |
|
|