@@ -4,6 +4,12 @@ const assert = require('assert');
44const picomatch = require ( '..' ) ;
55const { isMatch } = picomatch ;
66
7+ const assertTokens = ( actual , expected ) => {
8+ const keyValuePairs = actual . map ( ( token ) => [ token . type , token . value ] ) ;
9+
10+ assert . deepStrictEqual ( keyValuePairs , expected ) ;
11+ } ;
12+
713describe ( 'picomatch' , ( ) => {
814 describe ( 'validation' , ( ) => {
915 it ( 'should throw an error when invalid arguments are given' , ( ) => {
@@ -307,4 +313,38 @@ describe('picomatch', () => {
307313 assert ( isMatch ( 'a/b/c/.xyz.md' , 'a/b/c/.*.md' , { dot : true } ) ) ;
308314 } ) ;
309315 } ) ;
316+
317+ describe ( '.parse' , ( ) => {
318+ describe ( 'tokens' , ( ) => {
319+ it ( 'should return result for pattern that matched by fastpath' , ( ) => {
320+ const { tokens } = picomatch . parse ( 'a*.txt' ) ;
321+
322+ const expected = [
323+ [ 'bos' , '' ] ,
324+ [ 'text' , 'a' ] ,
325+ [ 'star' , '*' ] ,
326+ [ 'text' , '.txt' ]
327+ ] ;
328+
329+ assertTokens ( tokens , expected ) ;
330+ } ) ;
331+
332+ it ( 'should return result for pattern' , ( ) => {
333+ const { tokens } = picomatch . parse ( '{a,b}*' ) ;
334+
335+ const expected = [
336+ [ 'bos' , '' ] ,
337+ [ 'brace' , '{' ] ,
338+ [ 'text' , 'a' ] ,
339+ [ 'comma' , ',' ] ,
340+ [ 'text' , 'b' ] ,
341+ [ 'brace' , '}' ] ,
342+ [ 'star' , '*' ] ,
343+ [ 'maybe_slash' , '' ]
344+ ] ;
345+
346+ assertTokens ( tokens , expected ) ;
347+ } ) ;
348+ } ) ;
349+ } ) ;
310350} ) ;
0 commit comments