-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-path-escapeglob.js
More file actions
29 lines (25 loc) · 838 Bytes
/
test-path-escapeglob.js
File metadata and controls
29 lines (25 loc) · 838 Bytes
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
'use strict';
require('../common');
const assert = require('assert');
const path = require('path');
const samples = [
['file*.txt', 'file[*].txt'],
['file?.txt', 'file[?].txt'],
['file[abc].txt', 'file[[]abc[]].txt'],
['folder/**/*.txt', 'folder/[*][*]/[*].txt'],
['file{1,2}.txt', 'file[{]1,2[}].txt'],
['file[0-9]?.txt', 'file[[]0-9[]][?].txt'],
['C:\\Users\\*.txt', 'C:\\Users\\[*].txt'],
['?[]', '[?][[][]]'],
['[', '[[]'],
['[]', '[[][]]'],
['[', '[[]'],
['[*', '[[][*]'],
['[]a', '[[][]]a'],
];
for (const [pattern, expected] of samples) {
const actual = path.escapeGlob(pattern);
assert.strictEqual(actual, expected, `Expected ${pattern} to be escaped as ${expected}, got ${actual} instead`);
}
// Test for non-string input
assert.throws(() => path.escapeGlob(123), /.*must be of type string.*/);