@@ -251,6 +251,66 @@ describe('Metalsmith', function(){
251251 } )
252252 } )
253253
254+ describe ( '#match' , function ( ) {
255+ it ( 'should match a glob pattern' , function ( done ) {
256+ var m = Metalsmith ( fixture ( 'match' ) )
257+ m
258+ . process ( function ( err ) {
259+ if ( err ) done ( err )
260+ var matches = m . match ( '**/*.md' ) . join ( ',' )
261+ assert . equal ( matches , `index.md,${ path . join ( 'nested' , 'index.md' ) } ` )
262+ done ( )
263+ } )
264+ } )
265+
266+ it ( 'should support negation & OR patterns' , function ( done ) {
267+ var m = Metalsmith ( fixture ( 'match' ) )
268+ m
269+ . process ( function ( err ) {
270+ if ( err ) done ( err )
271+ var negationMatches = m . match ( '!index.md' ) . join ( ',' )
272+ var orMatches = m . match ( '*.{jpg,md}' ) . join ( ',' )
273+ assert . equal ( negationMatches , `.htaccess,team.jpg,${ path . join ( 'nested' , 'index.md' ) } ` )
274+ assert . equal ( orMatches , 'index.md,team.jpg' )
275+ done ( )
276+ } )
277+ } )
278+
279+ it ( 'should include dotfiles, unless specified otherwise' , function ( done ) {
280+ var m = Metalsmith ( fixture ( 'match' ) )
281+ m
282+ . process ( function ( err ) {
283+ if ( err ) done ( err )
284+ var matchesAll = m . match ( '**' ) . join ( ',' )
285+ var matchesNoDot = m . match ( '**' , { dot : false } ) . join ( ',' )
286+ assert . equal ( matchesAll , `.htaccess,index.md,team.jpg,${ path . join ( 'nested' , 'index.md' ) } ` )
287+ assert . equal ( matchesNoDot , `index.md,team.jpg,${ path . join ( 'nested' , 'index.md' ) } ` )
288+ done ( )
289+ } )
290+ } )
291+
292+
293+ // this test is included because micromatch has an obscure option called "windows",
294+ // which is set to true by default on Windows. Maintains compat with how Metalsmith 2.x functions
295+ it ( 'should not transform backslashes to forward slashes in the returned matches' , function ( done ) {
296+ var m = Metalsmith ( fixture ( 'match' ) )
297+ m
298+ . use ( function windowsPaths ( files ) {
299+ Object . keys ( files ) . forEach ( key => {
300+ if ( key . indexOf ( '/' ) === - 1 ) return
301+ files [ key . replace ( / \/ / g, '\\' ) ] = files [ key ]
302+ delete files [ key ]
303+ } )
304+ } )
305+ . process ( function ( err ) {
306+ if ( err ) done ( err )
307+ var matches = m . match ( '**/*.md' ) . join ( ',' )
308+ assert . equal ( matches , 'index.md,nested\\index.md' )
309+ done ( )
310+ } )
311+ } )
312+ } )
313+
254314 describe ( '#read' , function ( ) {
255315 it ( 'should read from a source directory' , function ( done ) {
256316 var m = Metalsmith ( fixture ( 'read' ) )
0 commit comments