@@ -14,6 +14,20 @@ chai.use(chaiAsPromised);
1414chai . use ( spies ) ;
1515const expect = chai . expect ;
1616
17+ const mockGetConfiguration =
18+ ( config = { showInformationMessages : true , expandBraces : false } ) => {
19+ return ( name ) => {
20+ switch ( name ) {
21+ case 'advancedNewFile' :
22+ return {
23+ get : ( configName ) => config [ configName ]
24+ } ;
25+ default :
26+ return { } ;
27+ }
28+ } ;
29+ } ;
30+
1731describe ( 'Advanced New File' , ( ) => {
1832 describe ( 'showInputBox' , ( ) => {
1933 it ( 'resolves with the path to input from workspace root' , async ( ) => {
@@ -280,20 +294,6 @@ describe('Advanced New File', () => {
280294 } ) ;
281295
282296 describe ( 'openFile' , ( ) => {
283- const mockGetConfiguration =
284- ( config = { showInformationMessages : true } ) => {
285- return ( name ) => {
286- switch ( name ) {
287- case 'advancedNewFile' :
288- return {
289- get : ( configName ) => config [ configName ]
290- } ;
291- default :
292- return { } ;
293- }
294- } ;
295- } ;
296-
297297 it ( 'attempts to open the file' , ( ) => {
298298 const textDocument = 'mock document' ;
299299 const openTextDocument = chai . spy ( ( ) => Promise . resolve ( textDocument ) ) ;
@@ -413,6 +413,58 @@ describe('Advanced New File', () => {
413413 } ) ;
414414 } ) ;
415415
416+ describe ( 'expandBraces' , ( ) => {
417+ context ( 'expandBraces setting is true' , ( ) => {
418+ const advancedNewFile =
419+ proxyquire ( '../src/extension' , {
420+ vscode : {
421+ workspace : {
422+ getConfiguration : mockGetConfiguration ( { expandBraces : true , showInformationMessages : true } )
423+ } ,
424+ }
425+ } ) as typeof AdvancedNewFile ;
426+
427+ it ( 'expands braces to an array' , ( ) => {
428+ const fileArray = advancedNewFile . expandBraces ( 'test/{subfolder1,subfolder2}/file{1,2}.{html,ts}' ) ;
429+ expect ( fileArray ) . to . deep . eq ( [
430+ 'test/subfolder1/file1.html' ,
431+ 'test/subfolder1/file1.ts' ,
432+ 'test/subfolder1/file2.html' ,
433+ 'test/subfolder1/file2.ts' ,
434+ 'test/subfolder2/file1.html' ,
435+ 'test/subfolder2/file1.ts' ,
436+ 'test/subfolder2/file2.html' ,
437+ 'test/subfolder2/file2.ts'
438+ ] ) ;
439+ } ) ;
440+
441+ it ( 'returns a single item array if there are no braces' , ( ) => {
442+ const fileArray = advancedNewFile . expandBraces ( 'test/file1.html' ) ;
443+ expect ( fileArray ) . to . deep . eq ( [
444+ 'test/file1.html'
445+ ] ) ;
446+ } ) ;
447+ } ) ;
448+
449+ context ( 'expandBraces setting is false' , ( ) => {
450+ const advancedNewFile =
451+ proxyquire ( '../src/extension' , {
452+ vscode : {
453+ workspace : {
454+ getConfiguration : mockGetConfiguration ( { expandBraces : false , showInformationMessages : true } )
455+ } ,
456+ }
457+ } ) as typeof AdvancedNewFile ;
458+
459+ it ( 'returns a single item array regardless of presence of braces' , ( ) => {
460+ const fileArray = advancedNewFile . expandBraces ( 'test/file{1,2}.html' ) ;
461+ expect ( fileArray ) . to . deep . eq ( [
462+ 'test/file{1,2}.html'
463+ ] ) ;
464+ } )
465+ } ) ;
466+ } ) ;
467+
416468 describe ( 'lastSelection' , ( ) => {
417469 context ( 'empty cache' , ( ) => {
418470 it ( 'is undefined' , ( ) => {
0 commit comments