forked from isaacs/minimatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescaping.js
52 lines (48 loc) · 1.39 KB
/
escaping.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
import tap from 'tap'
import { minimatch } from '../dist/esm/index.js'
// test all characters with codes in range [mincc,maxcc]
var mincc = 0x20
var maxcc = 0xff
// except listed in exceptions array
var exceptions = ['/', '\\']
var pre = 'x' // prepended to the testable character
var post = 'y' // appended to the testable character
function escapeChar(cc) {
return '"\\u' + ('000' + cc.toString(16).toUpperCase()).slice(-4) + '"'
}
tap.test('escaping tests', function (t) {
for (var cc = mincc; cc <= maxcc; ++cc) {
var cp = String.fromCharCode(cc)
if (exceptions.indexOf(cp) === -1) {
var str = pre + cp + post
var pattern = '*\\' + cp + '*'
var msg =
JSON.stringify(str) +
' (for codepoint ' +
escapeChar(cc) +
')' +
' should match pattern ' +
JSON.stringify(pattern)
t.equal(minimatch(str, pattern), true, msg)
}
}
t.end()
})
tap.test('class escaping tests', function (t) {
for (var cc = mincc; cc <= maxcc; ++cc) {
var cp = String.fromCharCode(cc)
if (exceptions.indexOf(cp) === -1) {
var str = pre + cp + post
var pattern = '*[\\' + cp + ']*'
var msg =
JSON.stringify(str) +
' (for codepoint ' +
escapeChar(cc) +
')' +
' should match pattern ' +
JSON.stringify(pattern)
t.equal(minimatch(str, pattern), true, msg)
}
}
t.end()
})