-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
test.js
95 lines (86 loc) · 5.66 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import test from 'ava';
import multimatch from '../index.js';
const fixtures = ['vendor/js/foo.js', 'vendor/js/bar.js', 'vendor/js/baz.js'];
test('match on multiple patterns', t => {
t.deepEqual(multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']), ['unicorn', 'rainbows']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']);
});
test('return an array of matches', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], 'foo'), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*', 'bar']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']);
});
test('return matches in the order the list were defined', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', 'f*']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*', '*z']), ['foo', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*z', 'f*']), ['foo', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z', '*r', 'f*']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*a*', '!f*']), ['bar', 'baz']);
});
test('return an array with negations omitted', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], '!foo'), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z', '!*a*']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*']), []);
t.deepEqual(multimatch(fixtures, ['!**/*z.js']), []);
t.deepEqual(multimatch(fixtures, ['!**/*z.js', '**/foo.js']), ['vendor/js/foo.js']);
t.deepEqual(multimatch(fixtures, ['!**/*z.js', '!**/*a*.js']), []);
});
test('return an empty array when no matches are found', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['quux']), []);
t.deepEqual(multimatch(fixtures, ['!**/*.js']), []);
});
test('patterns be order sensitive', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z']), ['baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*z', '!*a*']), []);
t.deepEqual(multimatch(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*']), ['foo', 'foam', 'for', 'forum']);
t.deepEqual(multimatch(['foo', 'foam', 'for', 'forum'], ['f*', '!*m']), ['foo', 'for']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar']), ['bar']);
});
test('override negations and re-include explicitly defined patterns', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', '!*a*']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', 'bar']), ['bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*']), ['foo', 'bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z']), ['baz']);
});
test('misc', t => {
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', 'bar']), ['bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '*']), ['foo', 'bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', '!bar']), ['baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*']), ['foo', 'bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}']), ['baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*']), ['foo', 'bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo']), ['foo', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo']), ['foo', 'bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}']), ['baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], 'foo'), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']);
t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []);
t.deepEqual(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once']), ['once']);
t.deepEqual(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once']), ['foo', 'two', 'four', 'do', 'once']);
});