-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathpathstringifier.test.ts
More file actions
40 lines (35 loc) · 1.15 KB
/
pathstringifier.test.ts
File metadata and controls
40 lines (35 loc) · 1.15 KB
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
import { parsePath, escapeKey } from './pathstringifier.js';
import { test, describe, it, expect } from 'vitest';
describe('parsePath', () => {
it.each([
['test.a.b', ['test', 'a', 'b']],
['test\\.a.b', ['test.a', 'b']],
['test\\\\.a.b', ['test\\.a', 'b']],
['test\\a.b', ['test\\a', 'b']],
['test\\\\a.b', ['test\\\\a', 'b']],
])('legacy parsePath(%p) === %p', (input, expectedOutput) => {
expect(parsePath(input, true)).toEqual(expectedOutput);
});
it.each([
['test.a.b', ['test', 'a', 'b']],
['test\\.a.b', ['test.a', 'b']],
['test\\\\.a.b', ['test\\', 'a', 'b']],
['test\\\\a.b', ['test\\a', 'b']],
])('parsePath(%p) === %p', (input, expectedOutput) => {
expect(parsePath(input, false)).toEqual(expectedOutput);
});
it.each(['test\\a.b', 'foo.bar.baz\\'])(
'parsePath(%p) is rejected',
input => {
expect(() => parsePath(input, false)).toThrowError();
}
);
});
describe('escapeKey', () => {
test.each([
['dontescape', 'dontescape'],
['escape.me', 'escape\\.me'],
])('escapeKey(%s) === %s', (input, expectedOutput) => {
expect(escapeKey(input)).toEqual(expectedOutput);
});
});