@@ -8,6 +8,16 @@ const both = (...args) => {
88 return [ base , glob ] ;
99} ;
1010
11+ /**
12+ * @param {String } pattern
13+ * @param {String[] } parts
14+ */
15+ function assertParts ( pattern , parts ) {
16+ const info = scan ( pattern , { parts : true } ) ;
17+
18+ assert . deepStrictEqual ( info . parts , parts ) ;
19+ }
20+
1121/**
1222 * Most of the unit tests in this file were from https://github.com/es128/glob-parent
1323 * and https://github.com/jonschlinkert/glob-base. Both libraries use a completely
@@ -252,6 +262,56 @@ describe('picomatch', () => {
252262 negated : false
253263 } ) ;
254264 } ) ;
265+
266+ it ( 'should return parts of the pattern' , ( ) => {
267+ // Right now it returns []
268+ // assertParts('', ['']);
269+ // assertParts('*', ['*']);
270+ // assertParts('.*', ['.*']);
271+ // assertParts('**', ['**']);
272+ // assertParts('foo', ['foo']);
273+ // assertParts('foo*', ['foo*']);
274+ // assertParts('/', ['', '']);
275+ // assertParts('/*', ['', '*']);
276+ // assertParts('./', ['']);
277+ // assertParts('{1..9}', ['{1..9}']);
278+ // assertParts('c!(.)z', ['c!(.)z']);
279+ // assertParts('(b|a).(a)', ['(b|a).(a)']);
280+ // assertParts('+(a|b\\[)*', ['+(a|b\\[)*']);
281+ // assertParts('@(a|b).md', ['@(a|b).md']);
282+ // assertParts('(a/b)', ['(a/b)']);
283+ // assertParts('(a\\b)', ['(a\\b)']);
284+ // assertParts('foo\\[a\\/]', ['foo\\[a\\/]']);
285+ // assertParts('foo[/]bar', ['foo[/]bar']);
286+ // assertParts('/dev\\/@(tcp|udp)\\/*\\/*', ['', '/dev\\/@(tcp|udp)\\/*\\/*']);
287+
288+ // Right now it returns ['*']
289+ // assertParts('*/', ['*', '']);
290+
291+ // Right now it returns ['!(!(bar)', 'baz)']
292+ // assertParts('!(!(bar)/baz)', ['!(!(bar)/baz)']);
293+
294+ assertParts ( './foo' , [ 'foo' ] ) ;
295+ assertParts ( '../foo' , [ '..' , 'foo' ] ) ;
296+
297+ assertParts ( 'foo/bar' , [ 'foo' , 'bar' ] ) ;
298+ assertParts ( 'foo/*' , [ 'foo' , '*' ] ) ;
299+ assertParts ( 'foo/**' , [ 'foo' , '**' ] ) ;
300+ assertParts ( 'foo/**/*' , [ 'foo' , '**' , '*' ] ) ;
301+ assertParts ( 'フォルダ/**/*' , [ 'フォルダ' , '**' , '*' ] ) ;
302+
303+ assertParts ( 'foo/!(abc)' , [ 'foo' , '!(abc)' ] ) ;
304+ assertParts ( 'c/!(z)/v' , [ 'c' , '!(z)' , 'v' ] ) ;
305+ assertParts ( 'c/@(z)/v' , [ 'c' , '@(z)' , 'v' ] ) ;
306+ assertParts ( 'foo/(bar|baz)' , [ 'foo' , '(bar|baz)' ] ) ;
307+ assertParts ( 'foo/(bar|baz)*' , [ 'foo' , '(bar|baz)*' ] ) ;
308+ assertParts ( '**/*(W*, *)*' , [ '**' , '*(W*, *)*' ] ) ;
309+ assertParts ( 'a/**@(/x|/z)/*.md' , [ 'a' , '**@(/x|/z)' , '*.md' ] ) ;
310+ assertParts ( 'foo/(bar|baz)/*.js' , [ 'foo' , '(bar|baz)' , '*.js' ] ) ;
311+
312+ assertParts ( 'XXX/*/*/12/*/*/m/*/*' , [ 'XXX' , '*' , '*' , '12' , '*' , '*' , 'm' , '*' , '*' ] ) ;
313+ assertParts ( 'foo/\\"**\\"/bar' , [ 'foo' , '\\"**\\"' , 'bar' ] ) ;
314+ } ) ;
255315 } ) ;
256316
257317 describe ( '.base (glob2base test patterns)' , ( ) => {
0 commit comments