forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs-paths.unit.test.ts
More file actions
116 lines (97 loc) · 4.42 KB
/
fs-paths.unit.test.ts
File metadata and controls
116 lines (97 loc) · 4.42 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:max-func-body-length
import { expect } from 'chai';
import * as path from 'path';
import * as TypeMoq from 'typemoq';
import { FileSystemPathUtils } from '../../../client/common/platform/fs-paths';
import { getNamesAndValues } from '../../../client/common/utils/enum';
import { OSType } from '../../../client/common/utils/platform';
interface IUtilsDeps {
// executables
delimiter: string;
envVar: string;
// paths
readonly sep: string;
join(...filenames: string[]): string;
dirname(filename: string): string;
basename(filename: string, suffix?: string): string;
normalize(filename: string): string;
normCase(filename: string): string;
// node "path"
relative(relpath: string, rootpath: string): string;
}
suite('FileSystem - Path Utils', () => {
let deps: TypeMoq.IMock<IUtilsDeps>;
let utils: FileSystemPathUtils;
setup(() => {
deps = TypeMoq.Mock.ofType<IUtilsDeps>(undefined, TypeMoq.MockBehavior.Strict);
utils = new FileSystemPathUtils(
'my-home',
// It's simpler to just use one mock for all 3 dependencies.
deps.object,
deps.object,
deps.object
);
});
function verifyAll() {
deps.verifyAll();
}
suite('path-related', () => {
const caseInsensitive = [OSType.Windows];
suite('arePathsSame', () => {
getNamesAndValues<OSType>(OSType).forEach((item) => {
const osType = item.value;
function setNormCase(filename: string, numCalls = 1): string {
let norm = filename;
if (osType === OSType.Windows) {
norm = path.normalize(filename).toUpperCase();
}
deps.setup((d) => d.normCase(filename))
.returns(() => norm)
.verifiable(TypeMoq.Times.exactly(numCalls));
return filename;
}
[
// no upper-case
'c:\\users\\peter smith\\my documents\\test.txt',
// some upper-case
'c:\\USERS\\Peter Smith\\my documents\\test.TXT'
].forEach((path1) => {
test(`True if paths are identical (type: ${item.name}) - ${path1}`, () => {
path1 = setNormCase(path1, 2);
const areSame = utils.arePathsSame(path1, path1);
expect(areSame).to.be.equal(true, 'file paths do not match');
verifyAll();
});
});
test(`False if paths are completely different (type: ${item.name})`, () => {
const path1 = setNormCase('c:\\users\\Peter Smith\\my documents\\test.txt');
const path2 = setNormCase('c:\\users\\Peter Smith\\my documents\\test.exe');
const areSame = utils.arePathsSame(path1, path2);
expect(areSame).to.be.equal(false, 'file paths do not match');
verifyAll();
});
if (caseInsensitive.includes(osType)) {
test(`True if paths only differ by case (type: ${item.name})`, () => {
const path1 = setNormCase('c:\\users\\Peter Smith\\my documents\\test.txt');
const path2 = setNormCase('c:\\USERS\\Peter Smith\\my documents\\test.TXT');
const areSame = utils.arePathsSame(path1, path2);
expect(areSame).to.be.equal(true, 'file paths match');
verifyAll();
});
} else {
test(`False if paths only differ by case (type: ${item.name})`, () => {
const path1 = setNormCase('c:\\users\\Peter Smith\\my documents\\test.txt');
const path2 = setNormCase('c:\\USERS\\Peter Smith\\my documents\\test.TXT');
const areSame = utils.arePathsSame(path1, path2);
expect(areSame).to.be.equal(false, 'file paths do not match');
verifyAll();
});
}
// Missing tests:
// * exercize normalization
});
});
});
});