-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathfsUtils.test.ts
124 lines (104 loc) · 4.58 KB
/
fsUtils.test.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as path from 'path';
import { isPathEqual, isSubpath } from '../extension.bundle';
suite('fsUtils', () => {
test('isPathEqual, posix, true', () => {
let fsPath1: string = '/test/';
let fsPath2: string = '/test/';
assert.equal(isPathEqual(fsPath1, fsPath2, path.posix.relative), true);
// path separator mismatch
fsPath1 = '/test/';
fsPath2 = '/test';
assert.equal(isPathEqual(fsPath1, fsPath2, path.posix.relative), true);
// flip order and try again
assert.equal(isPathEqual(fsPath2, fsPath1, path.posix.relative), true);
});
test('isPathEqual, win32, true', () => {
let fsPath1: string = 'C:\\test\\';
let fsPath2: string = 'C:\\test\\';
// path separator mismatch
fsPath1 = 'C:\\test\\';
fsPath2 = 'C:\\test';
assert.equal(isPathEqual(fsPath1, fsPath2, path.win32.relative), true);
// flip order and try again
assert.equal(isPathEqual(fsPath2, fsPath1, path.win32.relative), true);
// windows case insensitive path
fsPath1 = 'C:\\test\\';
fsPath2 = 'c:\\TEST\\';
assert.equal(isPathEqual(fsPath1, fsPath2, path.win32.relative), true);
});
test('isPathEqual, posix, false', () => {
let fsPath1: string = '/test/';
let fsPath2: string = '/test/a';
assert.equal(isPathEqual(fsPath1, fsPath2, path.posix.relative), false);
// flip order and try again
assert.equal(isPathEqual(fsPath2, fsPath1, path.posix.relative), false);
// completely different path
fsPath1 = '/test/sub';
fsPath2 = '/test2/sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), false);
});
test('isPathEqual, win32, false', () => {
let fsPath1: string = 'C:\\test\\a';
let fsPath2: string = 'C:\\test\\';
assert.equal(isPathEqual(fsPath1, fsPath2, path.win32.relative), false);
// flip order and try again
assert.equal(isPathEqual(fsPath2, fsPath1, path.win32.relative), false);
// completely different path
fsPath1 = 'C:\\test\\sub';
fsPath2 = 'D:\\test2\\sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), false);
});
test('isSubpath, posix, true', () => {
// sub path
let fsPath1: string = '/test/';
let fsPath2: string = '/test/sub';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), true);
// nested sub path
fsPath1 = '/test/';
fsPath2 = '/test/sub2/sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), true);
});
test('isSubpath, win32, true', () => {
// sub path
let fsPath1: string = 'C:\\test';
let fsPath2: string = 'C:\\test\\sub';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), true);
// nested sub path
fsPath1 = 'C:\\test';
fsPath2 = 'C:\\test\\sub\\sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), true);
});
test('isSubpath, posix, false', () => {
// opposite of subpath
let fsPath1: string = '/test/sub';
let fsPath2: string = '/test/';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), false);
// completely different path
fsPath1 = '/test/sub';
fsPath2 = '/test2/sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), false);
// same path
fsPath1 = '/test/';
fsPath2 = '/test/';
assert.equal(isSubpath(fsPath1, fsPath2, path.posix.relative), false);
});
test('isSubpath, win32, false', () => {
// opposite of subpath
let fsPath1: string = 'C:\\test\\sub\\';
let fsPath2: string = 'C:\\test\\';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), false);
// completely different path
fsPath1 = 'C:\\test\\sub';
fsPath2 = 'D:\\test2\\sub2';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), false);
// same path
fsPath1 = 'C:\\test\\';
fsPath2 = 'C:\\test\\';
assert.equal(isSubpath(fsPath1, fsPath2, path.win32.relative), false);
});
});