Skip to content

Commit 63baa4f

Browse files
committed
Define overload tests
1 parent 3a4a1e6 commit 63baa4f

2 files changed

Lines changed: 94 additions & 7 deletions

File tree

test/unit/overloads.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Expect, Test, TestCase } from "alsatian";
2+
3+
import * as util from "../src/util";
4+
5+
export class OverloadTests {
6+
7+
@Test("overload1")
8+
public overload1() {
9+
const lua = util.transpileString(
10+
`function abc(def: number): string;
11+
function abc(def: string): string;
12+
function abc(def: number | string): string {
13+
if (typeof def == "number") {
14+
return "jkl" + (def * 3);
15+
} else {
16+
return def;
17+
}
18+
}
19+
return abc(3);`);
20+
21+
const result = util.executeLua(lua);
22+
23+
Expect(result).toBe("jkl9");
24+
}
25+
26+
@Test("overload2")
27+
public overload2() {
28+
const lua = util.transpileString(
29+
`function abc(def: number): string;
30+
function abc(def: string): string;
31+
function abc(def: number | string): string {
32+
if (typeof def == "number") {
33+
return "jkl" + (def * 3);
34+
} else {
35+
return def;
36+
}
37+
}
38+
return abc("ghj");`);
39+
40+
const result = util.executeLua(lua);
41+
42+
Expect(result).toBe("ghj");
43+
}
44+
}
Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Expect, Test, TestCase, FocusTest } from "alsatian";
1+
import { Expect, Test, TestCase, FocusTests } from "alsatian";
22

33
import * as util from "../src/util";
44

5+
@FocusTests
56
export class OverloadTests {
6-
77
@TestCase("0")
88
@TestCase("30")
99
@TestCase("30_000")
1010
@TestCase("30.00")
1111
@Test("typeof number")
12-
@FocusTest
1312
public typeofNumberTest(inp: string) {
1413
const lua = util.transpileString(`return typeof ${inp};`);
1514
const result = util.executeLua(lua);
@@ -37,8 +36,8 @@ export class OverloadTests {
3736
Expect(result).toBe("boolean");
3837
}
3938

40-
@Test("{}")
41-
@Test("[]")
39+
@TestCase("{}")
40+
@TestCase("[]")
4241
@Test("typeof object literal")
4342
public typeofObjectLiteral(inp: string) {
4443
const lua = util.transpileString(`return typeof ${inp};`);
@@ -55,13 +54,57 @@ export class OverloadTests {
5554
Expect(result).toBe("table");
5655
}
5756

58-
@Test("null")
59-
@Test("undefined")
57+
@TestCase("null")
58+
@TestCase("undefined")
6059
@Test("typeof undefined")
6160
public typeofUndefinedTest(inp: string) {
6261
const lua = util.transpileString(`return typeof ${inp};`);
6362
const result = util.executeLua(lua);
6463

6564
Expect(result).toBe("nil");
6665
}
66+
67+
@Test("instanceof")
68+
public instanceOf() {
69+
const lua = util.transpileString("class myClass {} let inst = new myClass(); return inst instanceof myClass;");
70+
const result = util.executeLua(lua);
71+
72+
Expect(result).toBeTruthy();
73+
}
74+
75+
@Test("instanceof inheritance")
76+
public instanceOfInheritance() {
77+
const lua = util.transpileString("class myClass {}\n"
78+
+ "class childClass extends myClass{}\n"
79+
+ "let inst = new childClass(); return inst instanceof myClass;");
80+
const result = util.executeLua(lua);
81+
82+
Expect(result).toBeTruthy();
83+
}
84+
85+
@Test("instanceof inheritance false")
86+
public instanceOfInheritanceFalse() {
87+
const lua = util.transpileString("class myClass {}\n"
88+
+ "class childClass extends myClass{}\n"
89+
+ "let inst = new myClass(); return inst instanceof childClass;");
90+
const result = util.executeLua(lua);
91+
92+
Expect(result).toBeTruthy();
93+
}
94+
95+
@Test("null instanceof Object")
96+
public nullInstanceOf() {
97+
const lua = util.transpileString("return null instanceof Object;");
98+
const result = util.executeLua(lua);
99+
100+
Expect(result).toBe(false);
101+
}
102+
103+
@Test("null instanceof Class")
104+
public nullInstanceOfClass() {
105+
const lua = util.transpileString("class myClass {} return null instanceof myClass;");
106+
const result = util.executeLua(lua);
107+
108+
Expect(result).toBe(false);
109+
}
67110
}

0 commit comments

Comments
 (0)