GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TypeScriptToLua/test/unit/enum.spec.ts at master · TypeScriptToLua/TypeScriptToLua

Expand file tree

/

enum.spec.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
216 lines (182 loc) · 4.6 KB
/

enum.spec.ts

Copy path

File metadata and controls

216 lines (182 loc) · 4.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import * as util from "../util";
// TODO: string.toString()
const serializeEnum = (identifier: string) => `(() => {
const mappedTestEnum: any = {};
for (const key in ${identifier}) {
mappedTestEnum[(key as any).toString()] = (${identifier} as any)[key];
}
return mappedTestEnum;
})()`;
describe("initializers", () => {
test("string", () => {
util.testFunction`
enum TestEnum {
A = "A",
B = "B",
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("expression", () => {
util.testFunction`
const value = 6;
enum TestEnum {
A,
B = value,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("expression with side effect", () => {
util.testFunction`
let value = 0;
enum TestEnum {
A = value++,
B = A,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("inference", () => {
util.testFunction`
enum TestEnum {
A,
B,
C,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("partial inference", () => {
util.testFunction`
enum TestEnum {
A = 3,
B,
C = 5,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("member reference", () => {
util.testFunction`
enum TestEnum {
A,
B = A,
C = B,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("string literal member reference", () => {
util.testFunction`
enum TestEnum {
["A"],
"B" = A,
C = B,
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
});
describe("const enum", () => {
const expectToBeConst: util.TapCallback = builder =>
expect(builder.getMainLuaCodeChunk()).not.toContain("TestEnum");
test.each(["", "declare "])("%swithout initializer", modifier => {
util.testModule`
${modifier} const enum TestEnum {
A,
B,
}
export const A = TestEnum.A;
`
.tap(expectToBeConst)
.expectToMatchJsResult();
});
test("with string initializer", () => {
util.testFunction`
const enum TestEnum {
A = "ONE",
B = "TWO",
}
return TestEnum.A;
`
.tap(expectToBeConst)
.expectToMatchJsResult();
});
test("access with string literal", () => {
util.testFunction`
const enum TestEnum {
A,
B,
C,
}
return TestEnum["C"];
`
.tap(expectToBeConst)
.expectToMatchJsResult();
});
});
test("toString", () => {
util.testFunction`
enum TestEnum {
A,
B,
C,
}
function foo(value: TestEnum) {
return value.toString();
}
return foo(TestEnum.A);
`.expectToMatchJsResult();
});
test("enum merging", () => {
util.testFunction`
enum TestEnum {
A, B
}
enum TestEnum {
C = 3,
D
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("enum merging with overlap", () => {
util.testFunction`
enum TestEnum {
A, B
}
enum TestEnum {
C = 1,
D
}
return ${serializeEnum("TestEnum")}
`.expectToMatchJsResult();
});
test("enum merging multiple files", () => {
util.testModule`
import "./otherfile"
enum TestEnum {
A, B
}
export default ${serializeEnum("TestEnum")}
`
.addExtraFile(
"otherfile.ts",
`enum TestEnum {
C = 3,
D
}`
)
.expectToMatchJsResult();
});
test("enum nested in namespace", () => {
util.testModule`
namespace A {
export enum TestEnum {
B,
C
}
}
`.expectLuaToMatchSnapshot();
});
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.