forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramMissingFiles.ts
More file actions
103 lines (86 loc) · 4.43 KB
/
Copy pathprogramMissingFiles.ts
File metadata and controls
103 lines (86 loc) · 4.43 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
/// <reference path="..\harness.ts" />
namespace ts {
describe("Program.getMissingFilePaths", () => {
const options: CompilerOptions = {
noLib: true,
};
const emptyFileName = "empty.ts";
const emptyFileRelativePath = "./" + emptyFileName;
const emptyFile: Harness.Compiler.TestFile = {
unitName: emptyFileName,
content: ""
};
const referenceFileName = "reference.ts";
const referenceFileRelativePath = "./" + referenceFileName;
const referenceFile: Harness.Compiler.TestFile = {
unitName: referenceFileName,
content:
"/// <reference path=\"d:/imaginary/nonexistent1.ts\"/>\n" + // Absolute
"/// <reference path=\"./nonexistent2.ts\"/>\n" + // Relative
"/// <reference path=\"nonexistent3.ts\"/>\n" + // Unqualified
"/// <reference path=\"nonexistent4\"/>\n" // No extension
};
const testCompilerHost = Harness.Compiler.createCompilerHost(
/*inputFiles*/ [emptyFile, referenceFile],
/*writeFile*/ undefined,
/*scriptTarget*/ undefined,
/*useCaseSensitiveFileNames*/ false,
/*currentDirectory*/ "d:\\pretend\\",
/*newLineKind*/ NewLineKind.LineFeed,
/*libFiles*/ undefined
);
it("handles no missing root files", () => {
const program = createProgram([emptyFileRelativePath], options, testCompilerHost);
const missing = program.getMissingFilePaths();
assert.isDefined(missing);
assert.deepEqual(missing, []);
});
it("handles missing root file", () => {
const program = createProgram(["./nonexistent.ts"], options, testCompilerHost);
const missing = program.getMissingFilePaths();
assert.isDefined(missing);
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"]); // Absolute path
});
it("handles multiple missing root files", () => {
const program = createProgram(["./nonexistent0.ts", "./nonexistent1.ts"], options, testCompilerHost);
const missing = program.getMissingFilePaths().sort();
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"]);
});
it("handles a mix of present and missing root files", () => {
const program = createProgram(["./nonexistent0.ts", emptyFileRelativePath, "./nonexistent1.ts"], options, testCompilerHost);
const missing = program.getMissingFilePaths().sort();
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"]);
});
it("handles repeatedly specified root files", () => {
const program = createProgram(["./nonexistent.ts", "./nonexistent.ts"], options, testCompilerHost);
const missing = program.getMissingFilePaths();
assert.isDefined(missing);
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"]);
});
it("normalizes file paths", () => {
const program0 = createProgram(["./nonexistent.ts", "./NONEXISTENT.ts"], options, testCompilerHost);
const program1 = createProgram(["./NONEXISTENT.ts", "./nonexistent.ts"], options, testCompilerHost);
const missing0 = program0.getMissingFilePaths();
const missing1 = program1.getMissingFilePaths();
assert.equal(missing0.length, 1);
assert.deepEqual(missing0, missing1);
});
it("handles missing triple slash references", () => {
const program = createProgram([referenceFileRelativePath], options, testCompilerHost);
const missing = program.getMissingFilePaths().sort();
assert.isDefined(missing);
assert.deepEqual(missing, [
// From absolute reference
"d:/imaginary/nonexistent1.ts",
// From relative reference
"d:/pretend/nonexistent2.ts",
// From unqualified reference
"d:/pretend/nonexistent3.ts",
// From no-extension reference
"d:/pretend/nonexistent4.d.ts",
"d:/pretend/nonexistent4.ts",
"d:/pretend/nonexistent4.tsx"
]);
});
});
}