|
1 | 1 | /// <reference path="..\..\..\src\harness\harness.ts" />
|
2 | 2 | /// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
|
3 | 3 |
|
4 |
| -module ts { |
5 |
| - describe('parseConfigFileTextToJson', () => { |
6 |
| - function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) { |
7 |
| - let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); |
8 |
| - assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject)); |
9 |
| - } |
10 |
| - |
11 |
| - function assertParseError(jsonText: string) { |
12 |
| - let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); |
13 |
| - assert.isTrue(undefined === parsed.config); |
14 |
| - assert.isTrue(undefined !== parsed.error); |
15 |
| - } |
| 4 | +namespace ts { |
| 5 | + describe('parseConfigFileTextToJson', () => { |
| 6 | + function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) { |
| 7 | + let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); |
| 8 | + assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject)); |
| 9 | + } |
16 | 10 |
|
17 |
| - it("returns empty config for file with only whitespaces", () => { |
18 |
| - assertParseResult("", { config : {} }); |
19 |
| - assertParseResult(" ", { config : {} }); |
20 |
| - }); |
21 |
| - |
22 |
| - it("returns empty config for file with comments only", () => { |
23 |
| - assertParseResult("// Comment", { config: {} }); |
24 |
| - assertParseResult("/* Comment*/", { config: {} }); |
25 |
| - }); |
| 11 | + function assertParseError(jsonText: string) { |
| 12 | + let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); |
| 13 | + assert.isTrue(undefined === parsed.config); |
| 14 | + assert.isTrue(undefined !== parsed.error); |
| 15 | + } |
26 | 16 |
|
27 |
| - it("returns empty config when config is empty object", () => { |
28 |
| - assertParseResult("{}", { config: {} }); |
29 |
| - }); |
| 17 | + it("returns empty config for file with only whitespaces", () => { |
| 18 | + assertParseResult("", { config : {} }); |
| 19 | + assertParseResult(" ", { config : {} }); |
| 20 | + }); |
30 | 21 |
|
31 |
| - it("returns config object without comments", () => { |
32 |
| - assertParseResult( |
33 |
| - `{ // Excluded files |
34 |
| - "exclude": [ |
35 |
| - // Exclude d.ts |
36 |
| - "file.d.ts" |
37 |
| - ] |
38 |
| - }`, { config: { exclude: ["file.d.ts"] } }); |
39 |
| - |
40 |
| - assertParseResult( |
41 |
| - `{ |
42 |
| - /* Excluded |
43 |
| - Files |
44 |
| - */ |
45 |
| - "exclude": [ |
46 |
| - /* multiline comments can be in the middle of a line */"file.d.ts" |
47 |
| - ] |
48 |
| - }`, { config: { exclude: ["file.d.ts"] } }); |
49 |
| - }); |
| 22 | + it("returns empty config for file with comments only", () => { |
| 23 | + assertParseResult("// Comment", { config: {} }); |
| 24 | + assertParseResult("/* Comment*/", { config: {} }); |
| 25 | + }); |
50 | 26 |
|
51 |
| - it("keeps string content untouched", () => { |
52 |
| - assertParseResult( |
53 |
| - `{ |
54 |
| - "exclude": [ |
55 |
| - "xx//file.d.ts" |
56 |
| - ] |
57 |
| - }`, { config: { exclude: ["xx//file.d.ts"] } }); |
58 |
| - assertParseResult( |
59 |
| - `{ |
60 |
| - "exclude": [ |
61 |
| - "xx/*file.d.ts*/" |
62 |
| - ] |
63 |
| - }`, { config: { exclude: ["xx/*file.d.ts*/"] } }); |
64 |
| - }); |
65 |
| - |
66 |
| - it("handles escaped characters in strings correctly", () => { |
67 |
| - assertParseResult( |
68 |
| - `{ |
69 |
| - "exclude": [ |
70 |
| - "xx\\"//files" |
71 |
| - ] |
72 |
| - }`, { config: { exclude: ["xx\"//files"] } }); |
73 |
| - |
74 |
| - assertParseResult( |
75 |
| - `{ |
76 |
| - "exclude": [ |
77 |
| - "xx\\\\" // end of line comment |
78 |
| - ] |
79 |
| - }`, { config: { exclude: ["xx\\"] } }); |
80 |
| - }); |
81 |
| - |
82 |
| - it("returns object with error when json is invalid", () => { |
83 |
| - assertParseError("invalid"); |
| 27 | + it("returns empty config when config is empty object", () => { |
| 28 | + assertParseResult("{}", { config: {} }); |
| 29 | + }); |
| 30 | + |
| 31 | + it("returns config object without comments", () => { |
| 32 | + assertParseResult( |
| 33 | + `{ // Excluded files |
| 34 | + "exclude": [ |
| 35 | + // Exclude d.ts |
| 36 | + "file.d.ts" |
| 37 | + ] |
| 38 | + }`, { config: { exclude: ["file.d.ts"] } }); |
| 39 | + |
| 40 | + assertParseResult( |
| 41 | + `{ |
| 42 | + /* Excluded |
| 43 | + Files |
| 44 | + */ |
| 45 | + "exclude": [ |
| 46 | + /* multiline comments can be in the middle of a line */"file.d.ts" |
| 47 | + ] |
| 48 | + }`, { config: { exclude: ["file.d.ts"] } }); |
| 49 | + }); |
| 50 | + |
| 51 | + it("keeps string content untouched", () => { |
| 52 | + assertParseResult( |
| 53 | + `{ |
| 54 | + "exclude": [ |
| 55 | + "xx//file.d.ts" |
| 56 | + ] |
| 57 | + }`, { config: { exclude: ["xx//file.d.ts"] } }); |
| 58 | + assertParseResult( |
| 59 | + `{ |
| 60 | + "exclude": [ |
| 61 | + "xx/*file.d.ts*/" |
| 62 | + ] |
| 63 | + }`, { config: { exclude: ["xx/*file.d.ts*/"] } }); |
| 64 | + }); |
| 65 | + |
| 66 | + it("handles escaped characters in strings correctly", () => { |
| 67 | + assertParseResult( |
| 68 | + `{ |
| 69 | + "exclude": [ |
| 70 | + "xx\\"//files" |
| 71 | + ] |
| 72 | + }`, { config: { exclude: ["xx\"//files"] } }); |
| 73 | + |
| 74 | + assertParseResult( |
| 75 | + `{ |
| 76 | + "exclude": [ |
| 77 | + "xx\\\\" // end of line comment |
| 78 | + ] |
| 79 | + }`, { config: { exclude: ["xx\\"] } }); |
| 80 | + }); |
| 81 | + |
| 82 | + it("returns object with error when json is invalid", () => { |
| 83 | + assertParseError("invalid"); |
| 84 | + }); |
84 | 85 | });
|
85 |
| - }); |
86 | 86 | }
|
0 commit comments