UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

49 lines (47 loc) 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const testHelpers_1 = require("./../testHelpers"); describe("StatementedNode", () => { describe("getStatements", () => { it("should get the statements of a source file", () => { const { sourceFile } = testHelpers_1.getInfoFromText("var t; var m;"); chai_1.expect(sourceFile.getStatements().map(s => s.getText())).to.deep.equal(["var t;", "var m;"]); }); it("should get the statements of a function", () => { const { firstChild } = testHelpers_1.getInfoFromText("function i() { var t; var m; }"); chai_1.expect(firstChild.getStatements().map(s => s.getText())).to.deep.equal(["var t;", "var m;"]); }); it("should get the statements of a namespace", () => { const { firstChild } = testHelpers_1.getInfoFromText("namespace n { var t; var m; }"); chai_1.expect(firstChild.getStatements().map(s => s.getText())).to.deep.equal(["var t;", "var m;"]); }); it("should get the statements of a namespace that uses dot notation", () => { const { firstChild } = testHelpers_1.getInfoFromText("namespace n.inner { var t; var m; }"); chai_1.expect(firstChild.getStatements().map(s => s.getText())).to.deep.equal(["var t;", "var m;"]); }); }); describe("fill", () => { function doTest(startingCode, structure, expectedCode) { const { sourceFile } = testHelpers_1.getInfoFromText(startingCode); sourceFile.fill(structure); chai_1.expect(sourceFile.getText()).to.equal(expectedCode); } it("should not modify anything if the structure doesn't change anything", () => { doTest("", {}, ""); }); it("should modify when changed", () => { const structure = { classes: [{ name: "Identifier1" }], enums: [{ name: "Identifier2" }], functions: [{ name: "Identifier3" }], interfaces: [{ name: "Identifier4" }], namespaces: [{ name: "Identifier5" }], typeAliases: [{ name: "Identifier6", type: "string" }] }; doTest("", structure, "class Identifier1 {\n}\n\nenum Identifier2 {\n}\n\nfunction Identifier3() {\n}\n\ninterface Identifier4 {\n}\n\nnamespace Identifier5 {\n}\n\n" + "type Identifier6 = string;\n"); }); }); }); //# sourceMappingURL=statementedNodeTests.js.map