ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
41 lines (39 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const testHelpers_1 = require("./../testHelpers");
describe("BodiedNode", () => {
describe("setBodyText", () => {
function doTest(startCode, newText, expectedCode) {
const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(startCode);
firstChild.setBodyText(newText);
chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode);
}
function doWriterTest(startCode, writerFunc, expectedCode) {
const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(startCode);
firstChild.setBodyText(writerFunc);
chai_1.expect(sourceFile.getFullText()).to.equal(expectedCode);
}
// most of these tests are in bodyableNodeTests
it("should set the body text", () => {
doTest("namespace identifier {}", "var myVar;", "namespace identifier {\n var myVar;\n}");
});
it("should set the body text when using a writer", () => {
doWriterTest("namespace identifier {}", writer => writer.writeLine("test;").write("asdf;"), "namespace identifier {\n test;\n asdf;\n}");
});
});
describe("fill", () => {
function doTest(startCode, structure, expectedCode) {
const { firstChild, sourceFile } = testHelpers_1.getInfoFromText(startCode);
firstChild.fill(structure);
chai_1.expect(firstChild.getText()).to.equal(expectedCode);
}
it("should set the text when using a string", () => {
doTest("namespace identifier {\n}", { bodyText: "var myVar;" }, "namespace identifier {\n var myVar;\n}");
});
it("should set the text when using a writer", () => {
doTest("namespace identifier {\n}", { bodyText: writer => writer.writeLine("var myVar;") }, "namespace identifier {\n var myVar;\n}");
});
});
});
//# sourceMappingURL=bodiedNodeTests.js.map