@@ -9,21 +9,18 @@ const serializeEnum = (identifier: string) => `(() => {
99 return mappedTestEnum;
1010})()` ;
1111
12- // TODO: Move to namespace tests?
13- test ( "in a namespace" , ( ) => {
14- util . testModule `
15- namespace Test {
16- export enum TestEnum {
17- A,
18- B,
12+ describe ( "initializers" , ( ) => {
13+ test ( "string" , ( ) => {
14+ util . testFunction `
15+ enum TestEnum {
16+ A = "A",
17+ B = "B",
1918 }
20- }
2119
22- export const result = ${ serializeEnum ( "Test. TestEnum" ) }
23- ` . expectToMatchJsResult ( ) ;
24- } ) ;
20+ return ${ serializeEnum ( "TestEnum" ) }
21+ ` . expectToMatchJsResult ( ) ;
22+ } ) ;
2523
26- describe ( "initializers" , ( ) => {
2724 test ( "expression" , ( ) => {
2825 util . testFunction `
2926 const value = 6;
@@ -36,6 +33,18 @@ describe("initializers", () => {
3633 ` . expectToMatchJsResult ( ) ;
3734 } ) ;
3835
36+ test ( "expression with side effect" , ( ) => {
37+ util . testFunction `
38+ let value = 0;
39+ enum TestEnum {
40+ A = value++,
41+ B = A,
42+ }
43+
44+ return ${ serializeEnum ( "TestEnum" ) }
45+ ` . expectToMatchJsResult ( ) ;
46+ } ) ;
47+
3948 test ( "inference" , ( ) => {
4049 util . testFunction `
4150 enum TestEnum {
@@ -60,7 +69,7 @@ describe("initializers", () => {
6069 ` . expectToMatchJsResult ( ) ;
6170 } ) ;
6271
63- test ( "other member reference" , ( ) => {
72+ test ( "member reference" , ( ) => {
6473 util . testFunction `
6574 enum TestEnum {
6675 A,
@@ -71,26 +80,38 @@ describe("initializers", () => {
7180 return ${ serializeEnum ( "TestEnum" ) }
7281 ` . expectToMatchJsResult ( ) ;
7382 } ) ;
83+
84+ test ( "string literal member reference" , ( ) => {
85+ util . testFunction `
86+ enum TestEnum {
87+ ["A"],
88+ "B" = A,
89+ C = B,
90+ }
91+
92+ return ${ serializeEnum ( "TestEnum" ) }
93+ ` . expectToMatchJsResult ( ) ;
94+ } ) ;
7495} ) ;
7596
7697describe ( "const enum" , ( ) => {
7798 const expectToBeConst : util . TapCallback = builder =>
7899 expect ( builder . getMainLuaCodeChunk ( ) ) . not . toContain ( "TestEnum" ) ;
79100
80- test . each ( [ "" , "declare" ] ) ( "%s without initializer" , ( ) => {
81- util . testFunction `
82- const enum TestEnum {
101+ test . each ( [ "" , "declare " ] ) ( "%swithout initializer" , modifier => {
102+ util . testModule `
103+ ${ modifier } const enum TestEnum {
83104 A,
84105 B,
85106 }
86107
87- return TestEnum.A;
108+ export const A = TestEnum.A;
88109 `
89110 . tap ( expectToBeConst )
90111 . expectToMatchJsResult ( ) ;
91112 } ) ;
92113
93- test ( "with initializer" , ( ) => {
114+ test ( "with string initializer" , ( ) => {
94115 util . testFunction `
95116 const enum TestEnum {
96117 A = "ONE",
@@ -129,15 +150,3 @@ test("enum toString", () => {
129150 return test.toString();` ;
130151 expect ( util . transpileAndExecute ( code ) ) . toBe ( 0 ) ;
131152} ) ;
132-
133- test ( "enum concat" , ( ) => {
134- const code = `
135- enum TestEnum {
136- A,
137- B,
138- C,
139- }
140- let test = TestEnum.A;
141- return test + "_foobar";` ;
142- expect ( util . transpileAndExecute ( code ) ) . toBe ( "0_foobar" ) ;
143- } ) ;
0 commit comments