forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompileBooleanMatcher.unittest.js
80 lines (70 loc) · 2.01 KB
/
compileBooleanMatcher.unittest.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
"use strict";
const { itemsToRegexp } = require("../lib/util/compileBooleanMatcher");
describe("itemsToRegexp", () => {
const expectCompiled = (name, input, fn) => {
it(`should compile ${name}`, () => {
const items = typeof input === "string" ? input.split(",") : input;
const regexp = itemsToRegexp(items);
const r = new RegExp(`^${regexp}$`);
for (const item of items) {
expect(item).toMatch(r);
}
fn(expect(regexp));
});
};
expect.addSnapshotSerializer({
test() {
return true;
},
print(received) {
return received;
}
});
expectCompiled("basic", ["abc", "def", "123", "45", "6"], e =>
e.toMatchInlineSnapshot(`(123|45|6|abc|def)`)
);
expectCompiled("single chars", ["a", "b", "c", "1", "2", "3"], e =>
e.toMatchInlineSnapshot(`[123abc]`)
);
expectCompiled(
"prefixes",
["ab1", "ab2", "ab3", "ab4", "de5", "de6", "de7", "ef8", "ef9", "gh0"],
e => e.toMatchInlineSnapshot(`(ab[1234]|de[567]|ef[89]|gh0)`)
);
expectCompiled("short prefixes", "a,ab", e =>
e.toMatchInlineSnapshot(`a(|b)`)
);
expectCompiled(
"nested prefixes",
["a", "ab", "abc", "abcd", "abcde", "abcdef"],
e => e.toMatchInlineSnapshot(`a(b(c(d(|e|ef)|)|)|)`)
);
expectCompiled("suffixes", "a1,b1,c1,d1,e1,a2,b2,c2", e =>
e.toMatchInlineSnapshot(`([abcde]1|[abc]2)`)
);
expectCompiled(
"common prod",
"674,542,965,12,942,483,445,943,423,995,434,122,995,248,432,165,436,86,435,221",
e =>
e.toMatchInlineSnapshot(
`(1(2|22|65)|4(3[2456]|23|45|83)|9(42|43|65|95)|221|248|542|674|86)`
)
);
expectCompiled(
"long strings",
[
"./path/to/file.js",
"./path/to/file.mjs",
"./path/to/other-file.js",
"./path/to/directory/with/file.js",
"./path/to/directory/with/file.json",
"./path/to/directory/with/file.css",
"./path/to/directory/with/module.css",
"webpack/runtime/module"
],
e =>
e.toMatchInlineSnapshot(
`(\\.\\/path\\/to\\/(directory\\/with\\/(file\\.(js(|on)|css)|module\\.css)|file\\.(|m)js|other\\-file\\.js)|webpack\\/runtime\\/module)`
)
);
});