-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathminimatch.js
96 lines (82 loc) · 3.03 KB
/
minimatch.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
'use strict';
var path = require('path');
var assert = require('assert');
var isWindows = require('is-windows');
var patterns = require('./fixtures/patterns');
var mm = require('./support/match');
/**
* Minimatch comparison tests
*/
describe('basic tests', function() {
patterns.forEach(function(unit, i) {
it(i + ': ' + unit[0], function() {
if (typeof unit === 'string') {
console.log();
console.log(' ', unit);
return;
}
// update fixtures list
if (typeof unit === 'function') {
unit();
return;
}
var pattern = unit[0];
var expected = (unit[1] || []).sort(compare);
var options = Object.assign({}, unit[2]);
var fixtures = unit[3] || patterns.fixtures;
mm.match(fixtures, pattern, expected, options);
});
});
});
describe('minimatch parity:', function() {
describe('backslashes', function() {
it('should match literal backslashes', function() {
if (isWindows()) {
mm.match(['\\'], '\\', ['/']);
} else {
mm.match(['\\'], '\\', ['\\']);
}
});
});
/**
* Issues that minimatch fails on but micromatch passes
*/
describe('minimatch issues (as of 12/7/2016)', function() {
it('https://github.com/isaacs/minimatch/issues/29', function() {
assert(mm.isMatch('foo/bar.txt', 'foo/**/*.txt'));
assert(mm.makeRe('foo/**/*.txt').test('foo/bar.txt'));
});
it('https://github.com/isaacs/minimatch/issues/30', function() {
assert(mm.isMatch('foo/bar.js', '**/foo/**'));
assert(mm.isMatch('./foo/bar.js', './**/foo/**'));
assert(mm.isMatch('./foo/bar.js', '**/foo/**'));
assert(mm.isMatch('./foo/bar.txt', 'foo/**/*.txt'));
assert(mm.makeRe('./foo/**/*.txt').test('foo/bar.txt'));
});
it('https://github.com/isaacs/minimatch/issues/50', function() {
assert(mm.isMatch('foo/bar-[ABC].txt', 'foo/**/*-\\[ABC\\].txt'));
assert(!mm.isMatch('foo/bar-[ABC].txt', 'foo/**/*-\\[abc\\].txt'));
assert(mm.isMatch('foo/bar-[ABC].txt', 'foo/**/*-\\[abc\\].txt', {nocase: true}));
});
it('https://github.com/isaacs/minimatch/issues/67 (should work consistently with `makeRe` and matcher functions)', function() {
var re = mm.makeRe('node_modules/foobar/**/*.bar');
assert(re.test('node_modules/foobar/foo.bar'));
assert(mm.isMatch('node_modules/foobar/foo.bar', 'node_modules/foobar/**/*.bar'));
mm(['node_modules/foobar/foo.bar'], 'node_modules/foobar/**/*.bar', ['node_modules/foobar/foo.bar']);
});
it('https://github.com/isaacs/minimatch/issues/78', function() {
var sep = path.sep;
path.sep = '\\';
assert(mm.isMatch('a\\b\\c.txt', 'a/**/*.txt'));
assert(mm.isMatch('a/b/c.txt', 'a/**/*.txt'));
path.sep = sep;
});
it('https://github.com/isaacs/minimatch/issues/82', function() {
assert(mm.isMatch('./src/test/a.js', '**/test/**'));
assert(mm.isMatch('src/test/a.js', '**/test/**'));
});
});
});
function compare(a, b) {
return a === b ? 0 : a > b ? 1 : -1;
}