forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindingpatterns.spec.ts
More file actions
91 lines (82 loc) · 2.75 KB
/
Copy pathbindingpatterns.spec.ts
File metadata and controls
91 lines (82 loc) · 2.75 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
import { Expect, Test, TestCase, TestCases } from "alsatian";
import * as util from "../src/util";
const testCases = [
["{x}", "{x: true}", "x"],
["[x, y]", "[false, true]", "y"],
["{x: [y, z]}", "{x: [false, true]}", "z"],
["{x: [, z]}", "{x: [false, true]}", "z"],
["{x: [{y}]}", "{x: [{y: true}]}", "y"],
["[[y, z]]", "[[false, true]]", "z"],
["{x, y}", "{x: false, y: true}", "y"],
["{x: foo, y}", "{x: true, y: false}", "foo"],
["{x: foo, y: bar}", "{x: false, y: true}", "bar"],
["{x: {x, y}, z}", "{x: {x: true, y: false}, z: false}", "x"],
["{x: {x, y}, z}", "{x: {x: false, y: true}, z: false}", "y"],
["{x: {x, y}, z}", "{x: {x: false, y: false}, z: true}", "z"],
];
const testCasesDefault = [
["{x = true}", "{}", "x"],
["{x, y = true}", "{x: false}", "y"],
];
export class BindingPatternTests {
@TestCase("{x, y}, z", "{x: false, y: false}, true", "z")
@TestCase("{x, y}, {z}", "{x: false, y: false}, {z: true}", "z")
@TestCases(testCases)
@TestCases(testCasesDefault)
@Test("Object bindings in functions")
public tesBindingPatternParameters(
bindingString: string,
objectString: string,
returnVariable: string
): void {
const result = util.transpileAndExecute(`
function test(${bindingString}) {
return ${returnVariable};
}
return test(${objectString});
`);
Expect(result).toBe(true);
}
@TestCases(testCases)
@TestCases(testCasesDefault)
public testBindingPatternDeclarations(
bindingString: string,
objectString: string,
returnVariable: string
): void {
const result = util.transpileAndExecute(`
let ${bindingString} = ${objectString};
return ${returnVariable};
`);
Expect(result).toBe(true);
}
@TestCases(testCases)
@TestCases(testCasesDefault)
public testBindingPatternExportDeclarations(
bindingString: string,
objectString: string,
returnVariable: string
): void {
const result = util.transpileExecuteAndReturnExport(
`export const ${bindingString} = ${objectString};`,
returnVariable
);
Expect(result).toBe(true);
}
@TestCases(testCases)
@Test("Object bindings with call expressions")
public testBindingPatternCallExpressions(
bindingString: string,
objectString: string,
returnVariable: string
): void {
const result = util.transpileAndExecute(`
function call() {
return ${objectString};
}
let ${bindingString} = call();
return ${returnVariable};
`);
Expect(result).toBe(true);
}
}