forked from irinazheltisheva/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextpath.test.ts
More file actions
177 lines (152 loc) · 7.49 KB
/
Copy pathextpath.test.ts
File metadata and controls
177 lines (152 loc) · 7.49 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
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
/*---------------------------------------------------------------------------------------------
* 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 extpath from 'vs/base/common/extpath';
import * as platform from 'vs/base/common/platform';
import { CharCode } from 'vs/base/common/charCode';
suite('Paths', () => {
test('toForwardSlashes', () => {
assert.equal(extpath.toSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
assert.equal(extpath.toSlashes('c:\\test'), 'c:/test');
assert.equal(extpath.toSlashes('foo\\bar'), 'foo/bar');
assert.equal(extpath.toSlashes('/user/far'), '/user/far');
});
test('getRoot', () => {
assert.equal(extpath.getRoot('/user/far'), '/');
assert.equal(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/');
assert.equal(extpath.getRoot('//server/share/some/path'), '//server/share/');
assert.equal(extpath.getRoot('//server/share'), '/');
assert.equal(extpath.getRoot('//server'), '/');
assert.equal(extpath.getRoot('//server//'), '/');
assert.equal(extpath.getRoot('c:/user/far'), 'c:/');
assert.equal(extpath.getRoot('c:user/far'), 'c:');
assert.equal(extpath.getRoot('http://www'), '');
assert.equal(extpath.getRoot('http://www/'), 'http://www/');
assert.equal(extpath.getRoot('file:///foo'), 'file:///');
assert.equal(extpath.getRoot('file://foo'), '');
});
test('isUNC', () => {
if (platform.isWindows) {
assert.ok(!extpath.isUNC('foo'));
assert.ok(!extpath.isUNC('/foo'));
assert.ok(!extpath.isUNC('\\foo'));
assert.ok(!extpath.isUNC('\\\\foo'));
assert.ok(extpath.isUNC('\\\\a\\b'));
assert.ok(!extpath.isUNC('//a/b'));
assert.ok(extpath.isUNC('\\\\server\\share'));
assert.ok(extpath.isUNC('\\\\server\\share\\'));
assert.ok(extpath.isUNC('\\\\server\\share\\path'));
}
});
test('isValidBasename', () => {
assert.ok(!extpath.isValidBasename(null));
assert.ok(!extpath.isValidBasename(''));
assert.ok(extpath.isValidBasename('test.txt'));
assert.ok(!extpath.isValidBasename('/test.txt'));
assert.ok(!extpath.isValidBasename('\\test.txt'));
if (platform.isWindows) {
assert.ok(!extpath.isValidBasename('aux'));
assert.ok(!extpath.isValidBasename('Aux'));
assert.ok(!extpath.isValidBasename('LPT0'));
assert.ok(!extpath.isValidBasename('aux.txt'));
assert.ok(!extpath.isValidBasename('com0.abc'));
assert.ok(extpath.isValidBasename('LPT00'));
assert.ok(extpath.isValidBasename('aux1'));
assert.ok(extpath.isValidBasename('aux1.txt'));
assert.ok(extpath.isValidBasename('aux1.aux.txt'));
assert.ok(!extpath.isValidBasename('test.txt.'));
assert.ok(!extpath.isValidBasename('test.txt..'));
assert.ok(!extpath.isValidBasename('test.txt '));
assert.ok(!extpath.isValidBasename('test.txt\t'));
assert.ok(!extpath.isValidBasename('tes:t.txt'));
assert.ok(!extpath.isValidBasename('tes"t.txt'));
}
});
test('sanitizeFilePath', () => {
if (platform.isWindows) {
assert.equal(extpath.sanitizeFilePath('.', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.equal(extpath.sanitizeFilePath('', 'C:\\the\\cwd'), 'C:\\the\\cwd');
assert.equal(extpath.sanitizeFilePath('C:', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\\\', 'C:\\the\\cwd'), 'C:\\');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my.txt', 'C:\\the\\cwd'), 'C:\\folder\\my.txt');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\..\\my', 'C:\\the\\cwd'), 'C:\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('C:\\folder\\my\\\\\\', 'C:\\the\\cwd'), 'C:\\folder\\my');
assert.equal(extpath.sanitizeFilePath('my.txt', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.equal(extpath.sanitizeFilePath('my.txt\\', 'C:\\the\\cwd'), 'C:\\the\\cwd\\my.txt');
assert.equal(extpath.sanitizeFilePath('\\\\localhost\\folder\\my', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
assert.equal(extpath.sanitizeFilePath('\\\\localhost\\folder\\my\\', 'C:\\the\\cwd'), '\\\\localhost\\folder\\my');
} else {
assert.equal(extpath.sanitizeFilePath('.', '/the/cwd'), '/the/cwd');
assert.equal(extpath.sanitizeFilePath('', '/the/cwd'), '/the/cwd');
assert.equal(extpath.sanitizeFilePath('/', '/the/cwd'), '/');
assert.equal(extpath.sanitizeFilePath('/folder/my.txt', '/the/cwd'), '/folder/my.txt');
assert.equal(extpath.sanitizeFilePath('/folder/my', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('/folder/../my', '/the/cwd'), '/my');
assert.equal(extpath.sanitizeFilePath('/folder/my/', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('/folder/my///', '/the/cwd'), '/folder/my');
assert.equal(extpath.sanitizeFilePath('my.txt', '/the/cwd'), '/the/cwd/my.txt');
assert.equal(extpath.sanitizeFilePath('my.txt/', '/the/cwd'), '/the/cwd/my.txt');
}
});
test('isRoot', () => {
if (platform.isWindows) {
assert.ok(extpath.isRootOrDriveLetter('c:'));
assert.ok(extpath.isRootOrDriveLetter('D:'));
assert.ok(extpath.isRootOrDriveLetter('D:/'));
assert.ok(extpath.isRootOrDriveLetter('D:\\'));
assert.ok(!extpath.isRootOrDriveLetter('D:\\path'));
assert.ok(!extpath.isRootOrDriveLetter('D:/path'));
} else {
assert.ok(extpath.isRootOrDriveLetter('/'));
assert.ok(!extpath.isRootOrDriveLetter('/path'));
}
});
test('isWindowsDriveLetter', () => {
assert.ok(!extpath.isWindowsDriveLetter(0));
assert.ok(!extpath.isWindowsDriveLetter(-1));
assert.ok(extpath.isWindowsDriveLetter(CharCode.A));
assert.ok(extpath.isWindowsDriveLetter(CharCode.z));
});
test('indexOfPath', () => {
assert.equal(extpath.indexOfPath('/foo', '/bar', true), -1);
assert.equal(extpath.indexOfPath('/foo', '/FOO', false), -1);
assert.equal(extpath.indexOfPath('/foo', '/FOO', true), 0);
assert.equal(extpath.indexOfPath('/some/long/path', '/some/long', false), 0);
assert.equal(extpath.indexOfPath('/some/long/path', '/PATH', true), 10);
});
test('parseLineAndColumnAware', () => {
let res = extpath.parseLineAndColumnAware('/foo/bar');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
res = extpath.parseLineAndColumnAware('/foo/bar:33');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, 33);
assert.equal(res.column, 1);
res = extpath.parseLineAndColumnAware('/foo/bar:33:34');
assert.equal(res.path, '/foo/bar');
assert.equal(res.line, 33);
assert.equal(res.column, 34);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar:33');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, 33);
assert.equal(res.column, 1);
res = extpath.parseLineAndColumnAware('C:\\foo\\bar:33:34');
assert.equal(res.path, 'C:\\foo\\bar');
assert.equal(res.line, 33);
assert.equal(res.column, 34);
res = extpath.parseLineAndColumnAware('/foo/bar:abb');
assert.equal(res.path, '/foo/bar:abb');
assert.equal(res.line, undefined);
assert.equal(res.column, undefined);
});
});