-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #709 - Check and display syntax diagnostics when a manipulation…
… error occurs.
- Loading branch information
Showing
3 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/tests/manipulation/manipulations/doManipulationTests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from "chai"; | ||
import { getInfoFromText } from "../../compiler/testHelpers"; | ||
import { SyntaxKind } from "../../../typescript"; | ||
import { Block } from "../../../compiler"; | ||
|
||
describe("doManipulation", () => { | ||
it("should display the syntactic diagnostics if the user inserts a syntax error", () => { | ||
const { sourceFile } = getInfoFromText("if (true) {\n}"); | ||
const ifStatement = sourceFile.getStatementByKindOrThrow(SyntaxKind.IfStatement); | ||
const body = ifStatement.getThenStatement() as Block; | ||
let foundErr: any; | ||
try { | ||
body.addStatements("testing {"); | ||
} catch (err) { | ||
foundErr = err; | ||
} | ||
|
||
// don't bother with the rest because it will change between ts versions... | ||
const expectedText = `Manipulation error: A syntax error was inserted.`; | ||
const message: string = foundErr.message; | ||
expect(message.replace(/\u001b\[[0-9][0-9]?m/g, "").substring(0, expectedText.length)).to.equal(expectedText); | ||
}); | ||
}); |