-
Notifications
You must be signed in to change notification settings - Fork 71
/
match.js
102 lines (89 loc) · 3.24 KB
/
match.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
var assert = require("test/assert");
var file = require("file");
var util = require("narwhal/util");
util.forEachApply([
["", "", true],
["a", "a", true],
["?", "a", true],
["?", "b", true],
["?", "", false],
["?", "ab", false],
["??", "ab", true],
["*", "", true],
["*", "a", true],
["*", "ab", true],
["*.js", "ab", false],
["*.js", "ab.js", true],
["?git*", ".git", true],
["?git*", ".gitignore", true],
["*", "a/b", false],
["/*", "", false],
["/**", "", true],
["[ab]", "a", true],
["[ab]", "b", true],
["[ab]", "c", false],
["*.c{,pp,xx}", "a.c", true],
["*.c{,pp,xx}", "a.cpp", true],
["*.c{,pp,xx}", "a.cxx", true],
["*.c{,pp,xx}", "a.h", false],
// ["a{b{c}}", "abc", true], // needs to go context free
// ["a{/b/{c}}", "a/b/c", true],
["/a", "a", false],
["/a", "/a", true],
["...", ".", true],
[".../a", "./a", true],
[".../a", "../a", true],
[".../a", "../../a", true],
["[*]", "*", true],
[".", "*", false],
["?", "*", true],
["$", "$", true],
["^", "^", true],
[".", ".", true],
["/**/d.js", "/a/b/c/d.js", true],
["/b/**/d.js", "/a/b/c/d.js", false],
["/a/**/b.js", "/a/b.js", true],
["/**/...", "/", true],
// need ellipsis support for absolute paths ,
// and ** interactions
// ["/a/b/c/...", "/a/b/c/", true],
// ["/a/b/c/...", "/a/b/", true],
// ["/a/b/c/...", "/a/", true],
// ["/a/b/c/...", "/", true],
// ["a/b/c/...", "../..", true],
// ["a/b/c/...", "a/b/c", true],
// ["a/b/c/...", "a/b/c/d", false],
// ["/prefix/**/postfix", "/prefix/a/postfix", true],
// ["/prefix/**/postfix", "/prefix/postfix", true],
// ["/prefix/**/postfix", "/prefix/a", false],
// ["/prefix/**/postfix", "/postfix", false],
// ["/prefix/.../postfix", "/prefix/postfix", true],
// ["/prefix/.../postfix", "/postfix", true],
// ["/prefix/.../postfix", "/prefix/a/postfix", false],
// ["/prefix/.../postfix", "/", false],
// ["/pre/**/in/.../post", "/pre/in/no/post", true],
// ["/pre/**/in/.../post", "/pre/in/post", true],
// ["/pre/**/in/.../post", "/pre/no/post", true],
// ["/pre/**/in/.../post", "/pre/post", true],
// ["/pre/**/in/.../post", "/post", true],
// ["/pre/**/in/.../post", "/pre/in/no", false],
// ["/pre/**/in/.../post", "/pre", false],
// ["/pre/**/in/.../post", "/no/post", false],
// ["/pre/**/in/.../post", "/", false],
// ["/pre/.../in/**/post", "/pre/in/post", true],
// ["/pre/.../in/**/post", "/pre/in/no/post", true],
// ["/pre/.../in/**/post", "/in/post", true],
// ["/pre/.../in/**/post", "/in/no/post", true],
// ["/pre/.../in/**/post", "/post", false],
// ["/pre/.../in/**/post", "/no/in/post", false],
// ["/pre/.../in/**/post", "/pre/in/no", false],
// ["/pre/.../in/**/post", "/in/no", false]
], function (pattern, path, expected) {
exports['test ' + util.repr(arguments)] = function () {
//if (file.match(path, pattern) != expected)
// print('pattern: ' + util.repr(file.pattern));
assert.eq(expected, file.match(path, pattern));
};
});
if (require.main == module.id)
require("os").exit(require("test/runner").run(exports));