Skip to content

Commit 2b85ad4

Browse files
committed
Enum test
1 parent cf28eea commit 2b85ad4

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Expect, Test, TestCase } from "alsatian";
2+
3+
import * as util from "../src/util";
4+
5+
export class DecoratorTests {
6+
7+
@Test("RegularEnum")
8+
public regularEnum() {
9+
const lua = util.transpileFile("test/integration/testfiles/enum.ts");
10+
Expect(lua).toBe(
11+
"TestEnum={}\n"+
12+
"TestEnum.val1=0\n"+
13+
"TestEnum.val2=2\n"+
14+
"TestEnum.val3=3"
15+
);
16+
}
17+
18+
@Test("MembersOnlyEnumDecorator")
19+
public membersOnly() {
20+
const lua = util.transpileFile("test/integration/testfiles/membersOnlyEnum.ts");
21+
Expect(lua).toBe(
22+
"val1=0\n"+
23+
"val2=2\n"+
24+
"val3=3"
25+
);
26+
}
27+
}

test/integration/testfiles/enum.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum TestEnum {
2+
val1 = 0,
3+
val2 = 2,
4+
val3
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** !CompileMembersOnly */
2+
enum TestEnum {
3+
val1 = 0,
4+
val2 = 2,
5+
val3
6+
}

test/src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export function transpileString(str: string, dummyType: any): string {
1818
return result.trim();
1919
}
2020

21+
export function transpileFile(path: string): string {
22+
const program = ts.createProgram([path], {});
23+
const checker = program.getTypeChecker();
24+
25+
// Output errors
26+
const diagnostics = ts.getPreEmitDiagnostics(program).filter(diag => diag.code != 6054);
27+
diagnostics.forEach(diagnostic => console.log(`${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`));
28+
29+
const lua = LuaTranspiler.transpileSourceFile(program.getSourceFile(path), checker, true);
30+
return lua.trim();
31+
}
32+
2133
export function executeLua(lua: string, withLib = true): any {
2234
if (withLib) {
2335
lua = minimalTestLib + lua

0 commit comments

Comments
 (0)