UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

52 lines (50 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const testHelpers_1 = require("./../testHelpers"); describe("TypeParameterDeclaration", () => { function getTypeParameterFromText(text, index = 0) { const { firstChild } = testHelpers_1.getInfoFromText(text); return firstChild.getTypeParameters()[index]; } describe("getName", () => { it("should get the name", () => { const typeParameterDeclaration = getTypeParameterFromText("function func<T>() {}\n"); chai_1.expect(typeParameterDeclaration.getName()).to.equal("T"); }); }); describe("getConstraintNode", () => { it("should return undefined when there's no constraint", () => { const typeParameterDeclaration = getTypeParameterFromText("function func<T>() {}\n"); chai_1.expect(typeParameterDeclaration.getConstraintNode()).to.be.undefined; }); it("should return the constraint type node when there's a constraint", () => { const typeParameterDeclaration = getTypeParameterFromText("function func<T extends string>() {}\n"); chai_1.expect(typeParameterDeclaration.getConstraintNode().getText()).to.equal("string"); }); }); describe("remove", () => { function doTest(startText, indexToRemove, expectedText) { const typeParameterDeclaration = getTypeParameterFromText(startText, indexToRemove); const { sourceFile } = typeParameterDeclaration; typeParameterDeclaration.remove(); chai_1.expect(sourceFile.getFullText()).to.equal(expectedText); } it("should remove when its the only type parameter", () => { doTest("function func<T>() {}", 0, "function func() {}"); }); it("should remove when it's the first type parameter", () => { doTest("function func<T, U>() {}", 0, "function func<U>() {}"); }); it("should remove when it's the middle type parameter", () => { doTest("function func<T, U, V>() {}", 1, "function func<T, V>() {}"); }); it("should remove when it's the last type parameter", () => { doTest("function func<T, U>() {}", 1, "function func<T>() {}"); }); it("should remove when it has a constraint", () => { doTest("function func<T extends Other, U>() {}", 0, "function func<U>() {}"); }); }); }); //# sourceMappingURL=typeParameterDeclarationTests.js.map