-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
globule.js
56 lines (46 loc) · 2.26 KB
/
globule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Tests from [globule](https://github.com/cowboy/node-globule)
import test from 'ava';
import multimatch from '../index.js';
test('Should return empty set if a required argument is missing or an empty set.', t => {
t.deepEqual(multimatch('', 'foo.js'), []);
t.deepEqual(multimatch('*.js', ''), []);
t.deepEqual(multimatch([], 'foo.js'), []);
t.deepEqual(multimatch('*.js', []), []);
t.deepEqual(multimatch('', ['foo.js']), []);
t.deepEqual(multimatch(['*.js'], ''), []);
});
test('basic matching should match correctly', t => {
t.deepEqual(multimatch('foo.js', '*.js'), ['foo.js']);
t.deepEqual(multimatch(['foo.js'], '*.js'), ['foo.js']);
t.deepEqual(multimatch(['foo.js', 'bar.css'], '*.js'), ['foo.js']);
t.deepEqual(multimatch('foo.js', ['*.js', '*.css']), ['foo.js']);
t.deepEqual(multimatch(['foo.js'], ['*.js', '*.css']), ['foo.js']);
t.deepEqual(multimatch(['foo.js', 'bar.css'], ['*.js', '*.css']), ['foo.js', 'bar.css']);
});
test('should fail to match', t => {
t.deepEqual(multimatch('foo.css', '*.js'), []);
t.deepEqual(multimatch(['foo.css', 'bar.css'], '*.js'), []);
});
test('should return a uniqued set', t => {
t.deepEqual(multimatch(['foo.js', 'foo.js'], '*.js'), ['foo.js']);
t.deepEqual(multimatch(['foo.js', 'foo.js'], ['*.js', '*.*']), ['foo.js']);
});
test('solitary exclusion should match nothing', t => {
t.deepEqual(multimatch(['foo.js', 'bar.js'], ['!*.js']), []);
});
test('exclusion should cancel match', t => {
t.deepEqual(multimatch(['foo.js', 'bar.js'], ['*.js', '!*.js']), []);
});
test('partial exclusion should partially cancel match', t => {
t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js']), ['bar.js', 'baz.js']);
});
test('inclusion / exclusion order matters', t => {
t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js']), ['bar.js', 'baz.js']);
t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js']), ['foo.js', 'bar.js', 'baz.js']);
});
test('should matchBase (minimatch) when specified.', t => {
t.deepEqual(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true}), ['foo.js', 'baz/xyz.js']);
});
test('should not matchBase (minimatch) by default.', t => {
t.deepEqual(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js'), ['foo.js']);
});