Skip to content

fourslash diagnostics tests: use objects instead of strings #22193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,20 +1236,18 @@ Actual: ${stringify(fullActual)}`);
return this.languageService.findReferences(this.activeFile.fileName, this.currentCaretPosition);
}

public getSyntacticDiagnostics(expected: string) {
public getSyntacticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName);
this.testDiagnostics(expected, diagnostics);
}

public getSemanticDiagnostics(expected: string) {
public getSemanticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
const diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName);
this.testDiagnostics(expected, diagnostics);
}

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

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

public getSyntacticDiagnostics(expected: string) {
public getSyntacticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
this.state.getSyntacticDiagnostics(expected);
}

public getSemanticDiagnostics(expected: string) {
public getSemanticDiagnostics(expected: ReadonlyArray<ts.RealizedDiagnostic>) {
this.state.getSemanticDiagnostics(expected);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ namespace ts {
}
}

interface RealizedDiagnostic {
export interface RealizedDiagnostic {
message: string;
start: number;
length: number;
Expand Down
11 changes: 9 additions & 2 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ declare namespace FourSlashInterface {
start: number;
length: number;
}, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: ts.JSDocTagInfo[]): void;
getSyntacticDiagnostics(expected: string): void;
getSemanticDiagnostics(expected: string): void;
getSyntacticDiagnostics(expected: ReadonlyArray<RealizedDiagnostic>): void;
getSemanticDiagnostics(expected: ReadonlyArray<RealizedDiagnostic>): void;
ProjectInfo(expected: string[]): void;
allRangesAppearInImplementationList(markerName: string): void;
}
Expand Down Expand Up @@ -520,6 +520,13 @@ declare namespace FourSlashInterface {
text: string;
range: Range;
}
interface RealizedDiagnostic {
message: string;
start: number;
length: number;
category: string;
code: number;
}
}
declare function verifyOperationIsCancelled(f: any): void;
declare var test: FourSlashInterface.test_;
Expand Down
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// import a = b;

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'import ... =' can only be used in a .ts file.",
"start": 0,
"length": 13,
"category": "error",
"code": 8002
message: "'import ... =' can only be used in a .ts file.",
start: 0,
length: 13,
category: "error",
code: 8002
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// function F<T>() { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'type parameter declarations' can only be used in a .ts file.",
"start": 11,
"length": 1,
"category": "error",
"code": 8004
message: "'type parameter declarations' can only be used in a .ts file.",
start: 11,
length: 1,
category: "error",
code: 8004
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// function F(): number { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'types' can only be used in a .ts file.",
"start": 14,
"length": 6,
"category": "error",
"code": 8010
message: "'types' can only be used in a .ts file.",
start: 14,
length: 6,
category: "error",
code: 8010
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// declare var v;

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'declare' can only be used in a .ts file.",
"start": 0,
"length": 7,
"category": "error",
"code": 8009
message: "'declare' can only be used in a .ts file.",
start: 0,
length: 7,
category: "error",
code: 8009
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// var v: () => number;

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'types' can only be used in a .ts file.",
"start": 7,
"length": 12,
"category": "error",
"code": 8010
message: "'types' can only be used in a .ts file.",
start: 7,
length: 12,
category: "error",
code: 8010
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// Foo<number>();

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'type arguments' can only be used in a .ts file.",
"start": 4,
"length": 6,
"category": "error",
"code": 8011
message: "'type arguments' can only be used in a .ts file.",
start: 4,
length: 6,
category: "error",
code: 8011
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// function F(public p) { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'parameter modifiers' can only be used in a .ts file.",
"start": 11,
"length": 6,
"category": "error",
"code": 8012
message: "'parameter modifiers' can only be used in a .ts file.",
start: 11,
length: 6,
category: "error",
code: 8012
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// function F(p?) { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'?' can only be used in a .ts file.",
"start": 12,
"length": 1,
"category": "error",
"code": 8009
message: "'?' can only be used in a .ts file.",
start: 12,
length: 1,
category: "error",
code: 8009
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// function F(a: number) { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'types' can only be used in a .ts file.",
"start": 14,
"length": 6,
"category": "error",
"code": 8010
message: "'types' can only be used in a .ts file.",
start: 14,
length: 6,
category: "error",
code: 8010
}
]`);
]);
28 changes: 14 additions & 14 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
////}

goTo.file("a.js");
verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "\'public\' can only be used in a .ts file.",
"start": 93,
"length": 6,
"category": "error",
"code": 8009
message: "\'public\' can only be used in a .ts file.",
start: 93,
length: 6,
category: "error",
code: 8009
}
]`);
]);

// @Filename: b.js
////class C {
//// x: number; // Types not allowed
////}

goTo.file("b.js");
verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'types' can only be used in a .ts file.",
"start": 17,
"length": 6,
"category": "error",
"code": 8010
message: "'types' can only be used in a .ts file.",
start: 17,
length: 6,
category: "error",
code: 8010
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// enum E { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'enum declarations' can only be used in a .ts file.",
"start": 5,
"length": 1,
"category": "error",
"code": 8015
message: "'enum declarations' can only be used in a .ts file.",
start: 5,
length: 1,
category: "error",
code: 8015
}
]`);
]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// export = b;

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'export=' can only be used in a .ts file.",
"start": 0,
"length": 11,
"category": "error",
"code": 8003
message: "'export=' can only be used in a .ts file.",
start: 0,
length: 11,
category: "error",
code: 8003
}
]`);
]);
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// @Filename: a.js
//// @internal class C {}

verify.getSemanticDiagnostics(`[]`);
verify.getSemanticDiagnostics([]);
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// @Filename: a.js
//// function foo(...a) {}

verify.getSemanticDiagnostics(`[]`);
verify.getSemanticDiagnostics([]);
4 changes: 2 additions & 2 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
//// }
//// }

verify.getSyntacticDiagnostics(`[]`);
verify.getSemanticDiagnostics(`[]`);
verify.getSyntacticDiagnostics([]);
verify.getSemanticDiagnostics([]);
14 changes: 7 additions & 7 deletions tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// @Filename: a.js
//// class C<T> { }

verify.getSyntacticDiagnostics(`[
verify.getSyntacticDiagnostics([
{
"message": "'type parameter declarations' can only be used in a .ts file.",
"start": 8,
"length": 1,
"category": "error",
"code": 8004
message: "'type parameter declarations' can only be used in a .ts file.",
start: 8,
length: 1,
category: "error",
code: 8004
}
]`);
]);
Loading