@@ -8,6 +8,16 @@ const both = (...args) => {
8
8
return [ base , glob ] ;
9
9
} ;
10
10
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
+
11
21
/**
12
22
* Most of the unit tests in this file were from https://github.com/es128/glob-parent
13
23
* and https://github.com/jonschlinkert/glob-base. Both libraries use a completely
@@ -252,6 +262,56 @@ describe('picomatch', () => {
252
262
negated : false
253
263
} ) ;
254
264
} ) ;
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
+ } ) ;
255
315
} ) ;
256
316
257
317
describe ( '.base (glob2base test patterns)' , ( ) => {
0 commit comments