Skip to content

Commit 61adf0e

Browse files
committed
Added Tests for Function Expressions and Template Strings
1 parent c216ccc commit 61adf0e

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

test/unit/expressions.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,28 @@ export class ExpressionTests {
128128
public conditional(input: string, lua: string) {
129129
Expect(util.transpileString(input)).toBe(lua);
130130
}
131+
132+
@Test("Arrow Function Expression")
133+
public arrowFunctionExpression(input: string) {
134+
// Transpile
135+
const lua = util.transpileString(`let add = (a, b) => a+b; return add(1,2);`);
136+
137+
// Execute
138+
const result = util.executeLua(lua);
139+
140+
// Assert
141+
Expect(result).toBe(3);
142+
}
143+
144+
@Test("Function Expression")
145+
public functionExpression(input: string) {
146+
// Transpile
147+
const lua = util.transpileString(`let add = function(a, b) {return a+b}; return add(1,2);`);
148+
149+
// Execute
150+
const result = util.executeLua(lua);
151+
152+
// Assert
153+
Expect(result).toBe(3);
154+
}
131155
}

test/unit/string.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ export class StringTests {
2121
Expect(result).toBe(String.fromCharCode(...inp));
2222
}
2323

24+
@TestCase(12, 23, 43)
25+
@TestCase("test", "hello", "bye")
26+
@TestCase("test", 42, "bye")
27+
@TestCase("test", 42, 12)
28+
@Test("Template Strings")
29+
public templateStrings(a: any, b: any, c: any) {
30+
// Transpile
31+
const a1 = typeof(a) === "string" ? "'" + a + "'" : a;
32+
const b1 = typeof(b) === "string" ? "'" + b + "'" : b;
33+
const c1 = typeof(c) === "string" ? "'" + c + "'" : c;
34+
35+
let lua = util.transpileString(
36+
"let a = " + a1 + "; let b = " + b1 + "; let c = " + c1 + "; return `${a} ${b} test ${c}`;"
37+
);
38+
39+
// Execute
40+
let result = util.executeLua(lua);
41+
42+
// Assert
43+
Expect(result).toBe(`${a} ${b} test ${c}`);
44+
}
45+
2446
@TestCase("hello test", "", "")
2547
@TestCase("hello test", " ", "")
2648
@TestCase("hello test", "hello", "")

0 commit comments

Comments
 (0)