-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathapi.not.js
111 lines (96 loc) · 4.46 KB
/
api.not.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
var path = require('path');
var sep = path.sep;
var nm = require('./support/match');
describe('.not method', function() {
describe('posix paths', function() {
it('should return an array of matches for a literal string', function() {
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c'];
nm.not(fixtures, '(a/b)', ['a/a', 'a/c', 'b/a', 'b/b', 'b/c']);
nm.not(fixtures, 'a/b', ['a/a', 'a/c', 'b/a', 'b/b', 'b/c']);
});
it('should support regex logical or', function() {
var fixtures = ['a/a', 'a/b', 'a/c'];
nm.not(fixtures, 'a/(a|c)', ['a/b']);
nm.not(fixtures, 'a/(a|b|c)', []);
});
it('should support regex ranges', function() {
var fixtures = ['a/a', 'a/b', 'a/c', 'a/x/y', 'a/x'];
nm.not(fixtures, 'a/[b-c]', ['a/a', 'a/x/y', 'a/x']);
nm.not(fixtures, 'a/[a-z]', ['a/x/y']);
});
it('should support globs (*)', function() {
var fixtures = ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a', 'a/a/b', 'a/a/a/a', 'a/a/a/a/a'];
nm.not(fixtures, 'a/*', ['a/a/a', 'a/a/b', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/a', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/b', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a', 'a/a/b', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a', 'a/a/b', 'a/a/a/a']);
});
it('should support globstars (**)', function() {
var fixtures = ['a/a', 'a/b', 'a/c', 'a/x', 'a/x/y', 'a/x/y/z'];
nm.not(fixtures, 'a/**', []);
nm.not(fixtures, 'a/**/*', []);
nm.not(fixtures, 'a/**/**/*', []);
});
it('should support negation patterns', function() {
var fixtures = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c'];
nm.not(fixtures, '!a/b', ['a/b']);
nm.not(fixtures, '!a/(b)', ['a/b']);
nm.not(fixtures, '!(a/b)', ['a/b']);
});
});
describe('windows paths', function() {
beforeEach(function() {
path.sep = '\\';
});
afterEach(function() {
path.sep = sep;
});
it('should return an array of matches for a literal string', function() {
var fixtures = ['a', 'a\\a', 'a\\b', 'a\\c', 'b\\a', 'b\\b', 'b\\c'];
nm.not(fixtures, '(a/b)', ['a', 'a/a', 'a/c', 'b/a', 'b/b', 'b/c']);
nm.not(fixtures, 'a/b', ['a', 'a/a', 'a/c', 'b/a', 'b/b', 'b/c']);
});
it('should support regex logical or', function() {
var fixtures = ['a\\a', 'a\\b', 'a\\c'];
nm.not(fixtures, 'a/(a|c)', ['a/b']);
nm.not(fixtures, 'a/(a|b|c)', []);
});
it('should support regex ranges', function() {
var fixtures = ['.\\a\\a', 'a\\a', 'a\\b', 'a\\c', 'a\\x\\y', 'a\\x'];
nm.not(fixtures, '[a-c]/[a-c]', ['a/x', 'a/x/y']);
nm.not(fixtures, 'a/[b-c]', ['a/a', 'a/x', 'a/x/y']);
nm.not(fixtures, 'a/[a-z]', ['a/x/y']);
});
it('should support globs (*)', function() {
var fixtures = ['a\\a', 'a/a', 'a\\b', '.\\a\\b', 'a\\c', 'a\\x', 'a\\a\\a', 'a\\a\\b', 'a\\a\\a\\a', 'a\\a\\a\\a\\a'];
nm.not(fixtures, 'a/*', ['a/a/a', 'a/a/b', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/a', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/b', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a/a', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a', 'a/a/b', 'a/a/a/a/a']);
nm.not(fixtures, 'a/*/*/*/*', ['a/a', 'a/b', 'a/c', 'a/x', 'a/a/a', 'a/a/b', 'a/a/a/a']);
});
it('should support globstars (**)', function() {
var fixtures = ['a\\a', 'a\\b', 'a\\c', 'a\\x', 'a\\x\\y', 'a\\x\\y\\z'];
var expected = ['a/a', 'a/b', 'a/c', 'a/x', 'a/x/y', 'a/x/y/z'];
nm.not(fixtures, '*', expected);
nm.not(fixtures, '**', []);
nm.not(fixtures, '*/*', ['a/x/y', 'a/x/y/z']);
nm.not(fixtures, 'a/**', []);
nm.not(fixtures, 'a/x/**', ['a/a', 'a/b', 'a/c', 'a/x']);
nm.not(fixtures, 'a/**/*', []);
nm.not(fixtures, 'a/**/**/*', []);
});
it('should support negation patterns', function() {
var fixtures = ['a\\a', 'a\\b', 'a\\c', 'b\\a', 'b\\b', 'b\\c'];
var expected = ['a/a', 'a/b', 'a/c', 'b/a', 'b/b', 'b/c'];
nm.not(fixtures, '!**', expected);
nm.not(fixtures, '!*/*', expected);
nm.not(fixtures, '!*', []);
nm.not(fixtures, '!a/b', ['a/b']);
nm.not(fixtures, '!a/(b)', ['a/b']);
nm.not(fixtures, '!(a/b)', ['a/b']);
});
});
});