forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.spec.ts
More file actions
62 lines (56 loc) · 1.83 KB
/
plugins.spec.ts
File metadata and controls
62 lines (56 loc) · 1.83 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as path from "path";
import * as util from "../../util";
test("printer", () => {
util.testModule``
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "printer.ts") }] })
.tap(builder => expect(builder.getMainLuaCodeChunk()).toMatch("Plugin"));
});
test("visitor", () => {
util.testFunction`
return false;
`
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "visitor.ts") }] })
.expectToEqual(true);
});
test("visitor using super", () => {
util.testFunction`
return "foo";
`
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "visitor-super.ts") }] })
.expectToEqual("bar");
});
test("passing arguments", () => {
util.testFunction`
return {};
`
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "arguments.ts"), option: true }] })
.expectToEqual({ name: path.join(__dirname, "arguments.ts"), option: true });
});
test("statement comments", () => {
util.testFunction`
let foo = "bar";
foo = "baz";
while (true) {}
`
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "add-comments.ts") }] })
.expectLuaToMatchSnapshot();
});
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1013
test.each(["namespace", "module"])("%s with TS transformer plugin", moduleOrNamespace => {
util.testModule`
import { ns } from "module";
export const result = ns.returnsBool();
`
.addExtraFile(
"module.ts",
`
export ${moduleOrNamespace} ns {
export function returnsBool() {
return false;
}
}
`
)
.setOptions({ plugins: [{ transform: path.join(__dirname, "transformer-plugin.ts") }] })
.expectNoExecutionError();
});