Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f65651
commit c3bc209
Showing
15 changed files
with
280 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.all()', function() { | ||
it('should throw an error when value is not a string', function() { | ||
assert.throws(function() { | ||
mm.all(); | ||
}); | ||
}); | ||
|
||
it('should return true when all patterns match the given string', function() { | ||
assert(mm.all('z', ['z', '*', '[a-z]'])); | ||
assert(mm.all('b', 'b')); | ||
assert(mm.all('b', '*')); | ||
}); | ||
|
||
it('should return false when some patterns do not match', function() { | ||
assert(!mm.all('a', ['a', 'b', '*'])); | ||
}); | ||
|
||
it('should arrayify a string value', function() { | ||
assert(mm.all('a', ['*'])); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.braceExpand()', function() { | ||
it('should throw an error when arguments are invalid', function() { | ||
assert.throws(function() { | ||
mm.braceExpand(); | ||
}); | ||
}); | ||
|
||
it('should expand a brace pattern', function() { | ||
assert.deepEqual(mm.braceExpand('{a,b}'), ['a', 'b']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.braces()', function() { | ||
it('should throw an error when arguments are invalid', function() { | ||
assert.throws(function() { | ||
mm.braces(); | ||
}); | ||
}); | ||
|
||
it('should create a regex source string from a brace pattern', function() { | ||
assert.deepEqual(mm.braces('{a,b}'), ['(a|b)']); | ||
}); | ||
|
||
it('should expand a brace pattern', function() { | ||
assert.deepEqual(mm.braces('{a,b}', {expand: true}), ['a', 'b']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.compile()', function() { | ||
it('should throw an error when arguments are invalid', function() { | ||
assert.throws(function() { | ||
mm.compile(); | ||
}); | ||
}); | ||
|
||
it('should return an AST for a glob', function() { | ||
var foo = mm.compile('a/*'); | ||
delete foo.ast.state; | ||
assert.deepEqual(foo.ast, { | ||
type: 'root', | ||
errors: [], | ||
nodes: [ | ||
{ type: 'bos', val: '' }, | ||
{ type: 'text', val: 'a' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'star', val: '*' }, | ||
{ type: 'eos', val: '' } | ||
], | ||
input: 'a/*' | ||
}); | ||
|
||
var bar = mm.compile('a/**/*'); | ||
delete bar.ast.state; | ||
assert.deepEqual(bar.ast, { | ||
type: 'root', | ||
errors: [], | ||
nodes: [ | ||
{ type: 'bos', val: '' }, | ||
{ type: 'text', val: 'a' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'globstar', val: '**' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'star', val: '*' }, | ||
{ type: 'eos', val: '' } | ||
], | ||
input: 'a/**/*' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.every()', function() { | ||
it('should return true if every string matches', function() { | ||
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c']; | ||
assert(mm.every(fixtures, ['z', '*/*'])); | ||
}); | ||
|
||
it('should return false when not all strings match', function() { | ||
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c']; | ||
assert(!mm.every(fixtures, ['a/*', 'x/*'])); | ||
}); | ||
|
||
it('should arrayify a string value', function() { | ||
assert(mm.every('a', ['*'])); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.makeRe()', function() { | ||
it('should throw an error when value is not a string', function() { | ||
assert.throws(function() { | ||
mm.makeRe(); | ||
}); | ||
}); | ||
|
||
it('should create a regex for a glob pattern', function() { | ||
assert(mm.makeRe('*') instanceof RegExp); | ||
}); | ||
|
||
it('should create a regex for a string', function() { | ||
assert.deepEqual(mm.makeRe('abc').source, '^(?:abc)$'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.parse()', function() { | ||
it('should throw an error when arguments are invalid', function() { | ||
assert.throws(function() { | ||
mm.parse(); | ||
}); | ||
}); | ||
|
||
it('should return an AST for a glob', function() { | ||
var ast = mm.parse('a/*'); | ||
delete ast.state; | ||
assert.deepEqual(ast, { | ||
type: 'root', | ||
errors: [], | ||
nodes: [ | ||
{ type: 'bos', val: '' }, | ||
{ type: 'text', val: 'a' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'star', val: '*' }, | ||
{ type: 'eos', val: '' } | ||
], | ||
input: 'a/*' | ||
}); | ||
|
||
ast = mm.parse('a/**/*'); | ||
delete ast.state; | ||
assert.deepEqual(ast, { | ||
type: 'root', | ||
errors: [], | ||
nodes: [ | ||
{ type: 'bos', val: '' }, | ||
{ type: 'text', val: 'a' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'globstar', val: '**' }, | ||
{ type: 'slash', val: '/' }, | ||
{ type: 'star', val: '*' }, | ||
{ type: 'eos', val: '' } | ||
], | ||
input: 'a/**/*' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var mm = require('..'); | ||
|
||
describe('.some()', function() { | ||
it('should return true if any matches are found', function() { | ||
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c']; | ||
assert(mm.some(fixtures, ['z', 'b/*'])); | ||
}); | ||
|
||
it('should return false if no matches are found', function() { | ||
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c']; | ||
assert(!mm.some(fixtures, ['z', 'x/*'])); | ||
}); | ||
|
||
it('should arrayify a string value', function() { | ||
assert(mm.some('a', ['*'])); | ||
}); | ||
}); |