Skip to content

Commit 868cd76

Browse files
authored
Merge pull request #45 from Perryvw/feature/decorator-tests
Feature/decorator tests
2 parents 9f7739a + e6467e5 commit 868cd76

20 files changed

+128
-286
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Expect, Test, TestCase } from "alsatian";
2+
3+
import * as util from "../src/util";
4+
const fs = require("fs");
5+
6+
export class DecoratorTests {
7+
8+
// Expect the passed lua string to be equal to the file's contents.
9+
private ExpectEqualToFile(lua: string, path: string) {
10+
const expected = fs.readFileSync(path).toString();
11+
Expect(lua).toBe(expected.trim().split("\r\n").join("\n"));
12+
}
13+
14+
@Test("RegularEnum")
15+
public regularEnum() {
16+
const lua = util.transpileFile("test/integration/testfiles/enum.ts");
17+
this.ExpectEqualToFile(lua, "test/integration/testfiles/enum-expected.lua");
18+
}
19+
20+
@Test("MembersOnlyEnumDecorator")
21+
public membersOnly() {
22+
const lua = util.transpileFile("test/integration/testfiles/enumMembersOnly.ts");
23+
this.ExpectEqualToFile(lua, "test/integration/testfiles/enumMembersOnly-expected.lua");
24+
}
25+
26+
@Test("RegularClassExtend")
27+
public regularClassExtend() {
28+
const lua = util.transpileFile("test/integration/testfiles/class.ts");
29+
this.ExpectEqualToFile(lua, "test/integration/testfiles/class-expected.lua");
30+
}
31+
32+
@Test("PureAbstractClassExtend")
33+
public pureAbstractClassExtend() {
34+
const lua = util.transpileFile("test/integration/testfiles/classPureAbstract.ts");
35+
this.ExpectEqualToFile(lua, "test/integration/testfiles/classPureAbstract-expected.lua");
36+
}
37+
38+
@Test("ExtensionClass")
39+
public extensionClass() {
40+
const lua = util.transpileFile("test/integration/testfiles/classExtension.ts");
41+
this.ExpectEqualToFile(lua, "test/integration/testfiles/classExtension-expected.lua");
42+
}
43+
44+
@Test("RegularNamespace")
45+
public regularNamespace() {
46+
const lua = util.transpileFile("test/integration/testfiles/namespace.ts");
47+
this.ExpectEqualToFile(lua, "test/integration/testfiles/namespace-expected.lua");
48+
}
49+
50+
@Test("PhantomNamespace")
51+
public phantomNamespace() {
52+
const lua = util.transpileFile("test/integration/testfiles/namespacePhantom.ts");
53+
this.ExpectEqualToFile(lua, "test/integration/testfiles/namespacePhantom-expected.lua");
54+
}
55+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ClassB = ClassB or ClassA.new()
2+
ClassB.__index = ClassB
3+
ClassB.__base = ClassA
4+
function ClassB.new(construct, ...)
5+
local instance = setmetatable({}, ClassB)
6+
if construct and ClassB.constructor then ClassB.constructor(instance, ...) end
7+
return instance
8+
end
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,2 @@
1-
class testA {
2-
fieldA: number = 5;
3-
constructor(a: number) {
4-
this.fieldA = a;
5-
}
6-
7-
testMethod(): number {
8-
return this.fieldA;
9-
}
10-
}
11-
12-
class testB extends testA {
13-
fieldB: number;
14-
constructor(a: number, b: number) {
15-
super(a);
16-
this.fieldB = b;
17-
}
18-
19-
mul(): number {
20-
return this.fieldA * this.fieldB;
21-
}
22-
}
23-
24-
declare function print(...args:any[]): void;
25-
26-
let instance = new testB(4, 6);
27-
print(instance.fieldA);
28-
print(instance.fieldB);
29-
print(instance.mul());
1+
declare class ClassA {}
2+
class ClassB extends ClassA {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function MyClass.myFunction(self)
2+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** !Extension */
2+
class MyClass {
3+
myFunction() {}
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ClassB = ClassB or {}
2+
ClassB.__index = ClassB
3+
function ClassB.new(construct, ...)
4+
local instance = setmetatable({}, ClassB)
5+
if construct and ClassB.constructor then ClassB.constructor(instance, ...) end
6+
return instance
7+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/** !PureAbstract */
2+
declare class ClassA {}
3+
class ClassB extends ClassA {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TestEnum={}
2+
TestEnum.val1=0
3+
TestEnum.val2=2
4+
TestEnum.val3=3

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val1=0
2+
val2=2
3+
val3=3

0 commit comments

Comments
 (0)