forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverloads.spec.ts
More file actions
119 lines (105 loc) · 3.03 KB
/
Copy pathoverloads.spec.ts
File metadata and controls
119 lines (105 loc) · 3.03 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as util from "../util";
test("overload function1", () => {
const result = util.transpileAndExecute(
`function abc(def: number): string;
function abc(def: string): string;
function abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
return abc(3);`
);
expect(result).toBe("jkl9");
});
test("overload function2", () => {
const result = util.transpileAndExecute(
`function abc(def: number): string;
function abc(def: string): string;
function abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
return abc("ghj");`
);
expect(result).toBe("ghj");
});
test("overload method1", () => {
const result = util.transpileAndExecute(
`class myclass {
static abc(def: number): string;
static abc(def: string): string;
static abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
}
return myclass.abc(3);`
);
expect(result).toBe("jkl9");
});
test("overload method2", () => {
const result = util.transpileAndExecute(
`class myclass {
static abc(def: number): string;
static abc(def: string): string;
static abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
}
return myclass.abc("ghj");`
);
expect(result).toBe("ghj");
});
test("constructor1", () => {
const result = util.transpileAndExecute(
`class myclass {
num: number;
str: string;
constructor(def: number);
constructor(def: string);
constructor(def: number | string) {
if (typeof def == "number") {
this.num = def;
} else {
this.str = def;
}
}
}
const inst = new myclass(3);
return inst.num`
);
expect(result).toBe(3);
});
test("constructor2", () => {
const result = util.transpileAndExecute(
`class myclass {
num: number;
str: string;
constructor(def: number);
constructor(def: string);
constructor(def: number | string) {
if (typeof def == "number") {
this.num = def;
} else {
this.str = def;
}
}
}
const inst = new myclass("ghj");
return inst.str`
);
expect(result).toBe("ghj");
});