Skip to content

Commit ac6bcca

Browse files
author
Andy Hanson
committed
fourslash diagnostics tests: use objects instead of strings
1 parent d15b098 commit ac6bcca

29 files changed

+226
-212
lines changed

src/harness/fourslash.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,20 +1236,18 @@ Actual: ${stringify(fullActual)}`);
12361236
return this.languageService.findReferences(this.activeFile.fileName, this.currentCaretPosition);
12371237
}
12381238

1239-
public getSyntacticDiagnostics(expected: string) {
1239+
public getSyntacticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
12401240
const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName);
12411241
this.testDiagnostics(expected, diagnostics);
12421242
}
12431243

1244-
public getSemanticDiagnostics(expected: string) {
1244+
public getSemanticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
12451245
const diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName);
12461246
this.testDiagnostics(expected, diagnostics);
12471247
}
12481248

1249-
private testDiagnostics(expected: string, diagnostics: ReadonlyArray<ts.Diagnostic>) {
1250-
const realized = ts.realizeDiagnostics(diagnostics, "\r\n");
1251-
const actual = stringify(realized);
1252-
assert.equal(actual, expected);
1249+
private testDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>, diagnostics: ReadonlyArray<ts.Diagnostic>) {
1250+
assert.deepEqual(ts.realizeDiagnostics(diagnostics, ts.newLineCharacter), expected);
12531251
}
12541252

12551253
public verifyQuickInfoAt(markerName: string, expectedText: string, expectedDocumentation?: string) {
@@ -4321,11 +4319,11 @@ namespace FourSlashInterface {
43214319
this.state.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation, tags);
43224320
}
43234321

4324-
public getSyntacticDiagnostics(expected: string) {
4322+
public getSyntacticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
43254323
this.state.getSyntacticDiagnostics(expected);
43264324
}
43274325

4328-
public getSemanticDiagnostics(expected: string) {
4326+
public getSemanticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
43294327
this.state.getSemanticDiagnostics(expected);
43304328
}
43314329

src/services/shims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ namespace ts {
581581
}
582582
}
583583

584-
interface RealizedDiagnostic {
584+
export interface RealizedDiagnostic {
585585
message: string;
586586
start: number;
587587
length: number;

tests/cases/fourslash/fourslash.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ declare namespace FourSlashInterface {
347347
start: number;
348348
length: number;
349349
}, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: ts.JSDocTagInfo[]): void;
350-
getSyntacticDiagnostics(expected: string): void;
351-
getSemanticDiagnostics(expected: string): void;
350+
getSyntacticDiagnostics(expected: ReadonlyArray<RealizedDiagnostic>): void;
351+
getSemanticDiagnostics(expected: ReadonlyArray<RealizedDiagnostic>): void;
352352
ProjectInfo(expected: string[]): void;
353353
allRangesAppearInImplementationList(markerName: string): void;
354354
}
@@ -520,6 +520,13 @@ declare namespace FourSlashInterface {
520520
text: string;
521521
range: Range;
522522
}
523+
interface RealizedDiagnostic {
524+
message: string;
525+
start: number;
526+
length: number;
527+
category: string;
528+
code: number;
529+
}
523530
}
524531
declare function verifyOperationIsCancelled(f: any): void;
525532
declare var test: FourSlashInterface.test_;

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// import a = b;
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'import ... =' can only be used in a .ts file.",
10-
"start": 0,
11-
"length": 13,
12-
"category": "error",
13-
"code": 8002
9+
message: "'import ... =' can only be used in a .ts file.",
10+
start: 0,
11+
length: 13,
12+
category: "error",
13+
code: 8002
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// function F<T>() { }
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'type parameter declarations' can only be used in a .ts file.",
10-
"start": 11,
11-
"length": 1,
12-
"category": "error",
13-
"code": 8004
9+
message: "'type parameter declarations' can only be used in a .ts file.",
10+
start: 11,
11+
length: 1,
12+
category: "error",
13+
code: 8004
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// function F(): number { }
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'types' can only be used in a .ts file.",
10-
"start": 14,
11-
"length": 6,
12-
"category": "error",
13-
"code": 8010
9+
message: "'types' can only be used in a .ts file.",
10+
start: 14,
11+
length: 6,
12+
category: "error",
13+
code: 8010
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// declare var v;
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'declare' can only be used in a .ts file.",
10-
"start": 0,
11-
"length": 7,
12-
"category": "error",
13-
"code": 8009
9+
message: "'declare' can only be used in a .ts file.",
10+
start: 0,
11+
length: 7,
12+
category: "error",
13+
code: 8009
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// var v: () => number;
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'types' can only be used in a .ts file.",
10-
"start": 7,
11-
"length": 12,
12-
"category": "error",
13-
"code": 8010
9+
message: "'types' can only be used in a .ts file.",
10+
start: 7,
11+
length: 12,
12+
category: "error",
13+
code: 8010
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// Foo<number>();
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'type arguments' can only be used in a .ts file.",
10-
"start": 4,
11-
"length": 6,
12-
"category": "error",
13-
"code": 8011
9+
message: "'type arguments' can only be used in a .ts file.",
10+
start: 4,
11+
length: 6,
12+
category: "error",
13+
code: 8011
1414
}
15-
]`);
15+
]);

tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: a.js
55
//// function F(public p) { }
66

7-
verify.getSyntacticDiagnostics(`[
7+
verify.getSyntacticDiagnostics([
88
{
9-
"message": "'parameter modifiers' can only be used in a .ts file.",
10-
"start": 11,
11-
"length": 6,
12-
"category": "error",
13-
"code": 8012
9+
message: "'parameter modifiers' can only be used in a .ts file.",
10+
start: 11,
11+
length: 6,
12+
category: "error",
13+
code: 8012
1414
}
15-
]`);
15+
]);

0 commit comments

Comments
 (0)