/
decoratorStructurePrinterTests.ts
45 lines (37 loc) · 1.78 KB
/
decoratorStructurePrinterTests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { expect } from "chai";
import { FormatCodeSettings } from "../../../compiler";
import { DecoratorStructurePrinter } from "../../../structurePrinters";
import { DecoratorStructure, OptionalKind } from "../../../structures";
import { getStructureFactoryAndWriter } from "../../testHelpers";
describe(nameof(DecoratorStructurePrinter), () => {
interface Options {
formatCodeSettings?: FormatCodeSettings;
}
function doTest(structure: OptionalKind<DecoratorStructure>, expectedOutput: string, options: Options = {}) {
const { writer, factory } = getStructureFactoryAndWriter(options.formatCodeSettings);
factory.forDecorator().printText(writer, structure);
expect(writer.toString()).to.equal(expectedOutput);
}
// todo: more tests
describe(nameof<DecoratorStructurePrinter>(p => p.printText), () => {
describe("arguments", () => {
it("should write", () => {
doTest({ name: "dec", arguments: ["1", writer => writer.write("2")] }, `@dec(1, 2)`);
});
it("should write with a writer with queued child indentation", () => {
doTest({ name: "dec", arguments: writer => writer.writeLine("1,").write("2") }, `@dec(1,\n 2)`);
});
});
describe("type arguments", () => {
it("should not write when empty", () => {
doTest({ name: "dec", typeArguments: [] }, `@dec`);
});
it("should write", () => {
doTest({ name: "dec", typeArguments: ["string"], arguments: ["1"] }, `@dec<string>(1)`);
});
it("should write multiple", () => {
doTest({ name: "dec", typeArguments: ["string", "number"] }, `@dec<string, number>`);
});
});
});
});