ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
67 lines (65 loc) • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const testHelpers_1 = require("./../../testHelpers");
describe("AbstractableNode", () => {
describe("getAbstractKeyword", () => {
it("should get the abstract keyword when abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("abstract class Identifier {}");
chai_1.expect(firstChild.getAbstractKeyword().getText()).to.be.equal("abstract");
});
it("should return undefined when not abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("class Identifier {}");
chai_1.expect(firstChild.getAbstractKeyword()).to.be.undefined;
});
});
describe("getAbstractKeywordOrThrow", () => {
it("should get the abstract keyword when abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("abstract class Identifier {}");
chai_1.expect(firstChild.getAbstractKeywordOrThrow().getText()).to.be.equal("abstract");
});
it("should throw when not abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("class Identifier {}");
chai_1.expect(() => firstChild.getAbstractKeywordOrThrow()).to.throw();
});
});
describe("isAbstract", () => {
it("should be abstract when abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("abstract class Identifier {}");
chai_1.expect(firstChild.isAbstract()).to.be.true;
});
it("should be not abstract when not abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("class Identifier {}");
chai_1.expect(firstChild.isAbstract()).to.be.false;
});
});
describe("setIsAbstract", () => {
it("should be set to abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("class Identifier {}");
firstChild.setIsAbstract(true);
chai_1.expect(firstChild.getText()).to.equal("abstract class Identifier {}");
});
it("should be set to not abstract", () => {
const { firstChild } = testHelpers_1.getInfoFromText("abstract class Identifier {}");
firstChild.setIsAbstract(false);
chai_1.expect(firstChild.getText()).to.equal("class Identifier {}");
});
});
describe("fill", () => {
function doTest(startingCode, structure, expectedCode) {
const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(startingCode);
firstChild.fill(structure);
chai_1.expect(firstChild.getText()).to.equal(expectedCode);
}
it("should not modify anything if the structure doesn't change anything", () => {
doTest("class MyClass {}", {}, "class MyClass {}");
});
it("should not modify anything if the structure doesn't change anything and the node has everything set", () => {
doTest("abstract class MyClass {}", {}, "abstract class MyClass {}");
});
it("should modify when setting as abstract", () => {
doTest("class MyClass {}", { isAbstract: true }, "abstract class MyClass {}");
});
});
});
//# sourceMappingURL=abstractableNodeTests.js.map