-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdotfiles.js
144 lines (129 loc) · 6.66 KB
/
dotfiles.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
var assert = require('assert');
var nm = require('./support/match');
describe('dotfiles', function() {
describe('file name matching', function() {
it('should not match a dot when the dot is not explicitly defined', function() {
assert(!nm.isMatch('.dot', '*dot'));
assert(!nm.isMatch('a/.dot', 'a/*dot'));
});
it('should not match leading dots with question marks', function() {
assert(!nm.isMatch('.dot', '?dot'));
assert(!nm.isMatch('/.dot', '/?dot'));
assert(!nm.isMatch('a/.dot', 'a/?dot'));
});
it('should match with double dots', function() {
var fixtures = ['a/../a', 'ab/../ac', '../a', 'a', '../../b', '../c', '../c/d'];
nm(fixtures, '../*', ['../a', '../c']);
nm(fixtures, '*/../*', ['a/../a', 'ab/../ac']);
nm(fixtures, '**/../*', ['a/../a', 'ab/../ac', '../a', '../c']);
});
it('should not match a dot when the dot is not explicitly defined', function() {
var fixtures = ['a/b/.x', '.x', '.x/', '.x/a', '.x/a/b', '.x/.x', 'a/.x', 'a/b/.x/c', 'a/b/.x/c/d', 'a/b/.x/c/d/e', 'a/b/.x/', 'a/.x/b', 'a/.x/b/.x/c'];
nm(fixtures, '**/.x/**', ['.x/', '.x/a', '.x/a/b', 'a/b/.x/c', 'a/b/.x/c/d', 'a/b/.x/c/d/e', 'a/b/.x/', 'a/.x/b']);
});
it('should match a dot when the dot is explicitly defined', function() {
// first one is from minimatch tests
var fixtures = ['a/b/.x/c', 'a/b/.x/c/d', 'a/b/.x/c/d/e', 'a/b/.x', 'a/b/.x/', 'a/.x/b', '.x', '.x/', '.x/a', '.x/a/b', 'a/.x/b/.x/c', '.x/.x'];
var expected = ['.x/', '.x/a', '.x/a/b', 'a/.x/b', 'a/b/.x/', 'a/b/.x/c', 'a/b/.x/c/d', 'a/b/.x/c/d/e'];
nm(fixtures, '**/.x/**', expected);
nm('/.dot', '/[.]dot', ['/.dot']);
nm('.dot', '[.]dot', ['.dot']);
nm('.dot', '.[d]ot', ['.dot']);
nm('.dot', '.dot*', ['.dot']);
nm('.dot', '.d?t', ['.dot']);
assert(!nm.isMatch('.bar.baz', '.*.*/'));
assert(!nm.isMatch('/.dot', '*/[.]dot'));
assert(nm.isMatch('/.dot', '**/.[d]ot'));
assert(nm.isMatch('/.dot', '**/.dot*'));
assert(nm.isMatch('/.dot', '**/[.]dot'));
assert(nm.isMatch('.bar.baz/', '.*.*'));
assert(nm.isMatch('.bar.baz', '.*.*'));
assert(nm.isMatch('.bar.baz', '.*.baz'));
assert(nm.isMatch('.bar.baz/', '.*.*/'));
assert(nm.isMatch('.dot', '.*ot'));
assert(nm.isMatch('.dot', '.[d]ot'));
assert(nm.isMatch('.dot.foo.bar', '.*ot.*.*'));
assert(nm.isMatch('.dotfile.js', '.*.js'));
assert(nm.isMatch('/.dot', '/.[d]ot'));
assert(nm.isMatch('/.dot', '/.dot*'));
assert(nm.isMatch('/.dot', '/[.]dot'));
assert(nm.isMatch('a/.dot', '**/.[d]ot'));
assert(nm.isMatch('a/.dot', '*/.[d]ot'));
assert(nm.isMatch('a/.dot', '*/.dot*'));
assert(nm.isMatch('a/.dot', '*/[.]dot'));
assert(nm.isMatch('a/b/.dot', '**/.[d]ot'));
assert(nm.isMatch('a/b/.dot', '**/.dot*'));
assert(nm.isMatch('a/b/.dot', '**/[.]dot'));
assert(nm.isMatch('a/b/.dot', '.dot', {matchBase: true}));
assert(nm.isMatch('a/b/.dot', '[.]dot', {matchBase: true}));
});
});
describe('multiple directories', function() {
it('should not match a dot when the dot is not explicitly defined', function() {
assert(!nm.isMatch('.dot', '**/*dot'));
assert(!nm.isMatch('.dot', '**/?dot'));
assert(!nm.isMatch('.dot', '*/*dot'));
assert(!nm.isMatch('.dot', '*/?dot'));
assert(!nm.isMatch('.dot', '/*dot'));
assert(!nm.isMatch('.dot', '/?dot'));
assert(!nm.isMatch('/.dot', '**/*dot'));
assert(!nm.isMatch('/.dot', '**/?dot'));
assert(!nm.isMatch('/.dot', '*/*dot'));
assert(!nm.isMatch('/.dot', '*/?dot'));
assert(!nm.isMatch('/.dot', '/*dot'));
assert(!nm.isMatch('/.dot', '/?dot'));
assert(!nm.isMatch('a/.dot', '*/*dot'));
assert(!nm.isMatch('a/.dot', '*/?dot'));
assert(!nm.isMatch('a/b/.dot', '**/*dot'));
assert(!nm.isMatch('a/b/.dot', '**/?dot'));
// related https://github.com/jonschlinkert/micromatch/issues/63
assert(!nm.isMatch('/aaa/bbb/.git', '/aaa/bbb/**'));
assert(!nm.isMatch('aaa/bbb/.git', 'aaa/bbb/**'));
assert(!nm.isMatch('/aaa/bbb/ccc/.git', '/aaa/bbb/**'));
});
});
describe('options.dot', function() {
it('should match dotfiles when `options.dot` is true', function() {
assert(nm.isMatch('/a/b/.dot', '**/*dot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '**/.[d]ot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '**/?dot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '**/[.]dot', {dot: false}));
assert(nm.isMatch('/a/b/.dot', '**/[.]dot', {dot: true}));
assert(nm.isMatch('.dotfile.js', '.*.js', {dot: true}));
assert(nm.isMatch('.dot', '*dot', {dot: true}));
assert(nm.isMatch('.dot', '?dot', {dot: true}));
assert(nm.isMatch('.dot', '[.]dot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '/**/*dot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '/**/.[d]ot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '/**/?dot', {dot: true}));
assert(nm.isMatch('/a/b/.dot', '/**/[.]dot', {dot: false}));
assert(nm.isMatch('/a/b/.dot', '/**/[.]dot', {dot: true}));
assert(nm.isMatch('a/b/.dot', '**/*dot', {dot: true}));
assert(nm.isMatch('a/b/.dot', '**/.[d]ot', {dot: true}));
assert(nm.isMatch('a/b/.dot', '**/?dot', {dot: true}));
assert(nm.isMatch('a/b/.dot', '**/[.]dot', {dot: false}));
assert(nm.isMatch('a/b/.dot', '**/[.]dot', {dot: true}));
});
it('should match dotfiles when `.dot` and `.matchBase` both defined', function() {
assert(nm.isMatch('a/b/.dot', '*dot', {dot: true, matchBase: true}));
assert(nm.isMatch('a/b/.dot', '[.]dot', {dot: true, matchBase: true}));
assert(nm.isMatch('a/b/.dot', '[.]dot', {dot: false, matchBase: true}));
assert(nm.isMatch('a/b/.dot', '?dot', {dot: true, matchBase: true}));
});
it('should not match dotfiles when `options.dot` is false', function() {
assert(!nm.isMatch('a/b/.dot', '**/*dot', {dot: false}));
assert(!nm.isMatch('a/b/.dot', '**/?dot', {dot: false}));
});
it('should not match dotfiles when `.dot` is false and `.matchBase` is true', function() {
assert(!nm.isMatch('a/b/.dot', '*dot', {dot: false, matchBase: true}));
assert(!nm.isMatch('a/b/.dot', '?dot', {dot: false, matchBase: true}));
});
it('should not match dotfiles when `.dot` is not defined and a dot is not in the glob pattern', function() {
assert(!nm.isMatch('a/b/.dot', '*dot', {matchBase: true}));
assert(!nm.isMatch('a/b/.dot', '?dot', {matchBase: true}));
assert(!nm.isMatch('a/b/.dot', '**/*dot'));
assert(!nm.isMatch('a/b/.dot', '**/?dot'));
});
});
});