forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.test.ts
188 lines (154 loc) · 8.88 KB
/
files.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*---------------------------------------------------------------------------------------------
* 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 { URI } from 'vs/base/common/uri';
import { join, isEqual, isEqualOrParent } from 'vs/base/common/paths';
import { FileChangeType, FileChangesEvent, isParent } from 'vs/platform/files/common/files';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
suite('Files', () => {
function toResource(path) {
return URI.file(join('C:\\', path));
}
test('FileChangesEvent', () => {
let changes = [
{ resource: URI.file(join('C:\\', '/foo/updated.txt')), type: FileChangeType.UPDATED },
{ resource: URI.file(join('C:\\', '/foo/otherupdated.txt')), type: FileChangeType.UPDATED },
{ resource: URI.file(join('C:\\', '/added.txt')), type: FileChangeType.ADDED },
{ resource: URI.file(join('C:\\', '/bar/deleted.txt')), type: FileChangeType.DELETED },
{ resource: URI.file(join('C:\\', '/bar/folder')), type: FileChangeType.DELETED }
];
let r1 = new FileChangesEvent(changes);
assert(!r1.contains(toResource('/foo'), FileChangeType.UPDATED));
assert(r1.contains(toResource('/foo/updated.txt'), FileChangeType.UPDATED));
assert(!r1.contains(toResource('/foo/updated.txt'), FileChangeType.ADDED));
assert(!r1.contains(toResource('/foo/updated.txt'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder/somefile'), FileChangeType.DELETED));
assert(r1.contains(toResource('/bar/folder/somefile/test.txt'), FileChangeType.DELETED));
assert(!r1.contains(toResource('/bar/folder2/somefile'), FileChangeType.DELETED));
assert.strictEqual(5, r1.changes.length);
assert.strictEqual(1, r1.getAdded().length);
assert.strictEqual(true, r1.gotAdded());
assert.strictEqual(2, r1.getUpdated().length);
assert.strictEqual(true, r1.gotUpdated());
assert.strictEqual(2, r1.getDeleted().length);
assert.strictEqual(true, r1.gotDeleted());
});
function testIsEqual(testMethod: (pA: string | null | undefined, pB: string, ignoreCase: boolean) => boolean): void {
// corner cases
assert(testMethod('', '', true));
assert(!testMethod(null, '', true));
assert(!testMethod(void 0, '', true));
// basics (string)
assert(testMethod('/', '/', true));
assert(testMethod('/some', '/some', true));
assert(testMethod('/some/path', '/some/path', true));
assert(testMethod('c:\\', 'c:\\', true));
assert(testMethod('c:\\some', 'c:\\some', true));
assert(testMethod('c:\\some\\path', 'c:\\some\\path', true));
assert(testMethod('/someöäü/path', '/someöäü/path', true));
assert(testMethod('c:\\someöäü\\path', 'c:\\someöäü\\path', true));
assert(!testMethod('/some/path', '/some/other/path', true));
assert(!testMethod('c:\\some\\path', 'c:\\some\\other\\path', true));
assert(!testMethod('c:\\some\\path', 'd:\\some\\path', true));
assert(testMethod('/some/path', '/some/PATH', true));
assert(testMethod('/someöäü/path', '/someÖÄÜ/PATH', true));
assert(testMethod('c:\\some\\path', 'c:\\some\\PATH', true));
assert(testMethod('c:\\someöäü\\path', 'c:\\someÖÄÜ\\PATH', true));
assert(testMethod('c:\\some\\path', 'C:\\some\\PATH', true));
}
test('isEqual (ignoreCase)', function () {
testIsEqual(isEqual);
// basics (uris)
assert(isEqual(URI.file('/some/path').fsPath, URI.file('/some/path').fsPath, true));
assert(isEqual(URI.file('c:\\some\\path').fsPath, URI.file('c:\\some\\path').fsPath, true));
assert(isEqual(URI.file('/someöäü/path').fsPath, URI.file('/someöäü/path').fsPath, true));
assert(isEqual(URI.file('c:\\someöäü\\path').fsPath, URI.file('c:\\someöäü\\path').fsPath, true));
assert(!isEqual(URI.file('/some/path').fsPath, URI.file('/some/other/path').fsPath, true));
assert(!isEqual(URI.file('c:\\some\\path').fsPath, URI.file('c:\\some\\other\\path').fsPath, true));
assert(isEqual(URI.file('/some/path').fsPath, URI.file('/some/PATH').fsPath, true));
assert(isEqual(URI.file('/someöäü/path').fsPath, URI.file('/someÖÄÜ/PATH').fsPath, true));
assert(isEqual(URI.file('c:\\some\\path').fsPath, URI.file('c:\\some\\PATH').fsPath, true));
assert(isEqual(URI.file('c:\\someöäü\\path').fsPath, URI.file('c:\\someÖÄÜ\\PATH').fsPath, true));
assert(isEqual(URI.file('c:\\some\\path').fsPath, URI.file('C:\\some\\PATH').fsPath, true));
});
test('isParent (ignorecase)', function () {
if (isWindows) {
assert(isParent('c:\\some\\path', 'c:\\', true));
assert(isParent('c:\\some\\path', 'c:\\some', true));
assert(isParent('c:\\some\\path', 'c:\\some\\', true));
assert(isParent('c:\\someöäü\\path', 'c:\\someöäü', true));
assert(isParent('c:\\someöäü\\path', 'c:\\someöäü\\', true));
assert(isParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar', true));
assert(isParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\', true));
assert(isParent('c:\\some\\path', 'C:\\', true));
assert(isParent('c:\\some\\path', 'c:\\SOME', true));
assert(isParent('c:\\some\\path', 'c:\\SOME\\', true));
assert(!isParent('c:\\some\\path', 'd:\\', true));
assert(!isParent('c:\\some\\path', 'c:\\some\\path', true));
assert(!isParent('c:\\some\\path', 'd:\\some\\path', true));
assert(!isParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\barr', true));
assert(!isParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\test', true));
}
if (isMacintosh || isLinux) {
assert(isParent('/some/path', '/', true));
assert(isParent('/some/path', '/some', true));
assert(isParent('/some/path', '/some/', true));
assert(isParent('/someöäü/path', '/someöäü', true));
assert(isParent('/someöäü/path', '/someöäü/', true));
assert(isParent('/foo/bar/test.ts', '/foo/bar', true));
assert(isParent('/foo/bar/test.ts', '/foo/bar/', true));
assert(isParent('/some/path', '/SOME', true));
assert(isParent('/some/path', '/SOME/', true));
assert(isParent('/someöäü/path', '/SOMEÖÄÜ', true));
assert(isParent('/someöäü/path', '/SOMEÖÄÜ/', true));
assert(!isParent('/some/path', '/some/path', true));
assert(!isParent('/foo/bar/test.ts', '/foo/barr', true));
assert(!isParent('/foo/bar/test.ts', '/foo/bar/test', true));
}
});
test('isEqualOrParent (ignorecase)', function () {
// same assertions apply as with isEqual()
testIsEqual(isEqualOrParent);
if (isWindows) {
assert(isEqualOrParent('c:\\some\\path', 'c:\\', true));
assert(isEqualOrParent('c:\\some\\path', 'c:\\some', true));
assert(isEqualOrParent('c:\\some\\path', 'c:\\some\\', true));
assert(isEqualOrParent('c:\\someöäü\\path', 'c:\\someöäü', true));
assert(isEqualOrParent('c:\\someöäü\\path', 'c:\\someöäü\\', true));
assert(isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar', true));
assert(isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\', true));
assert(isEqualOrParent('c:\\some\\path', 'c:\\some\\path', true));
assert(isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\test.ts', true));
assert(isEqualOrParent('c:\\some\\path', 'C:\\', true));
assert(isEqualOrParent('c:\\some\\path', 'c:\\SOME', true));
assert(isEqualOrParent('c:\\some\\path', 'c:\\SOME\\', true));
assert(!isEqualOrParent('c:\\some\\path', 'd:\\', true));
assert(!isEqualOrParent('c:\\some\\path', 'd:\\some\\path', true));
assert(!isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\barr', true));
assert(!isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\test', true));
assert(!isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\bar\\test.', true));
assert(!isEqualOrParent('c:\\foo\\bar\\test.ts', 'c:\\foo\\BAR\\test.', true));
}
if (isMacintosh || isLinux) {
assert(isEqualOrParent('/some/path', '/', true));
assert(isEqualOrParent('/some/path', '/some', true));
assert(isEqualOrParent('/some/path', '/some/', true));
assert(isEqualOrParent('/someöäü/path', '/someöäü', true));
assert(isEqualOrParent('/someöäü/path', '/someöäü/', true));
assert(isEqualOrParent('/foo/bar/test.ts', '/foo/bar', true));
assert(isEqualOrParent('/foo/bar/test.ts', '/foo/bar/', true));
assert(isEqualOrParent('/some/path', '/some/path', true));
assert(isEqualOrParent('/some/path', '/SOME', true));
assert(isEqualOrParent('/some/path', '/SOME/', true));
assert(isEqualOrParent('/someöäü/path', '/SOMEÖÄÜ', true));
assert(isEqualOrParent('/someöäü/path', '/SOMEÖÄÜ/', true));
assert(!isEqualOrParent('/foo/bar/test.ts', '/foo/barr', true));
assert(!isEqualOrParent('/foo/bar/test.ts', '/foo/bar/test', true));
assert(!isEqualOrParent('foo/bar/test.ts', 'foo/bar/test.', true));
assert(!isEqualOrParent('foo/bar/test.ts', 'foo/BAR/test.', true));
}
});
});