1- import * as ts from "typescript" ;
2- import * as tstl from "../../../src" ;
3- import { UnsupportedNonDestructuringLuaIterator } from "../../../src/transformation/utils/errors" ;
41import * as util from "../../util" ;
52
63test ( "forof lua iterator" , ( ) => {
@@ -16,12 +13,7 @@ test("forof lua iterator", () => {
1613 for (let e of luaIter()) { result += e; }
1714 return result;
1815 ` ;
19- const compilerOptions = {
20- luaLibImport : tstl . LuaLibImportKind . Require ,
21- luaTarget : tstl . LuaTarget . Lua53 ,
22- target : ts . ScriptTarget . ES2015 ,
23- } ;
24- const result = util . transpileAndExecute ( code , compilerOptions ) ;
16+ const result = util . transpileAndExecute ( code ) ;
2517 expect ( result ) . toBe ( "abc" ) ;
2618} ) ;
2719
@@ -38,12 +30,7 @@ test("forof array lua iterator", () => {
3830 for (let e of luaIter()) { result += e; }
3931 return result;
4032 ` ;
41- const compilerOptions = {
42- luaLibImport : tstl . LuaLibImportKind . Require ,
43- luaTarget : tstl . LuaTarget . Lua53 ,
44- target : ts . ScriptTarget . ES2015 ,
45- } ;
46- const result = util . transpileAndExecute ( code , compilerOptions ) ;
33+ const result = util . transpileAndExecute ( code ) ;
4734 expect ( result ) . toBe ( "abc" ) ;
4835} ) ;
4936
@@ -61,12 +48,7 @@ test("forof lua iterator with existing variable", () => {
6148 for (e of luaIter()) { result += e; }
6249 return result;
6350 ` ;
64- const compilerOptions = {
65- luaLibImport : tstl . LuaLibImportKind . Require ,
66- luaTarget : tstl . LuaTarget . Lua53 ,
67- target : ts . ScriptTarget . ES2015 ,
68- } ;
69- const result = util . transpileAndExecute ( code , compilerOptions ) ;
51+ const result = util . transpileAndExecute ( code ) ;
7052 expect ( result ) . toBe ( "abc" ) ;
7153} ) ;
7254
@@ -83,12 +65,7 @@ test("forof lua iterator destructuring", () => {
8365 for (let [a, b] of luaIter()) { result += a + b; }
8466 return result;
8567 ` ;
86- const compilerOptions = {
87- luaLibImport : tstl . LuaLibImportKind . Require ,
88- luaTarget : tstl . LuaTarget . Lua53 ,
89- target : ts . ScriptTarget . ES2015 ,
90- } ;
91- const result = util . transpileAndExecute ( code , compilerOptions ) ;
68+ const result = util . transpileAndExecute ( code ) ;
9269 expect ( result ) . toBe ( "0a1b2c" ) ;
9370} ) ;
9471
@@ -107,12 +84,7 @@ test("forof lua iterator destructuring with existing variables", () => {
10784 for ([a, b] of luaIter()) { result += a + b; }
10885 return result;
10986 ` ;
110- const compilerOptions = {
111- luaLibImport : tstl . LuaLibImportKind . Require ,
112- luaTarget : tstl . LuaTarget . Lua53 ,
113- target : ts . ScriptTarget . ES2015 ,
114- } ;
115- const result = util . transpileAndExecute ( code , compilerOptions ) ;
87+ const result = util . transpileAndExecute ( code ) ;
11688 expect ( result ) . toBe ( "0a1b2c" ) ;
11789} ) ;
11890
@@ -134,12 +106,7 @@ test("forof lua iterator tuple-return", () => {
134106 for (let [a, b] of luaIter()) { result += a + b; }
135107 return result;
136108 ` ;
137- const compilerOptions = {
138- luaLibImport : tstl . LuaLibImportKind . Require ,
139- luaTarget : tstl . LuaTarget . Lua53 ,
140- target : ts . ScriptTarget . ES2015 ,
141- } ;
142- const result = util . transpileAndExecute ( code , compilerOptions ) ;
109+ const result = util . transpileAndExecute ( code ) ;
143110 expect ( result ) . toBe ( "0a1b2c" ) ;
144111} ) ;
145112
@@ -163,37 +130,24 @@ test("forof lua iterator tuple-return with existing variables", () => {
163130 for ([a, b] of luaIter()) { result += a + b; }
164131 return result;
165132 ` ;
166- const compilerOptions = {
167- luaLibImport : tstl . LuaLibImportKind . Require ,
168- luaTarget : tstl . LuaTarget . Lua53 ,
169- target : ts . ScriptTarget . ES2015 ,
170- } ;
171- const result = util . transpileAndExecute ( code , compilerOptions ) ;
133+ const result = util . transpileAndExecute ( code ) ;
172134 expect ( result ) . toBe ( "0a1b2c" ) ;
173135} ) ;
174136
175137test ( "forof lua iterator tuple-return single variable" , ( ) => {
176- const code = `
138+ util . testModule `
177139 /**
178140 * @luaIterator
179141 * @tupleReturn
180142 */
181143 interface Iter extends Iterable<[string, string]> {}
182144 declare function luaIter(): Iter;
183145 for (let x of luaIter()) {}
184- ` ;
185- const compilerOptions = {
186- luaLibImport : tstl . LuaLibImportKind . Require ,
187- luaTarget : tstl . LuaTarget . Lua53 ,
188- target : ts . ScriptTarget . ES2015 ,
189- } ;
190- expect ( ( ) => util . transpileString ( code , compilerOptions ) ) . toThrowExactError (
191- UnsupportedNonDestructuringLuaIterator ( util . nodeStub )
192- ) ;
146+ ` . expectDiagnosticsToMatchSnapshot ( ) ;
193147} ) ;
194148
195149test ( "forof lua iterator tuple-return single existing variable" , ( ) => {
196- const code = `
150+ util . testModule `
197151 /**
198152 * @luaIterator
199153 * @tupleReturn
@@ -202,15 +156,7 @@ test("forof lua iterator tuple-return single existing variable", () => {
202156 declare function luaIter(): Iter;
203157 let x: [string, string];
204158 for (x of luaIter()) {}
205- ` ;
206- const compilerOptions = {
207- luaLibImport : tstl . LuaLibImportKind . Require ,
208- luaTarget : tstl . LuaTarget . Lua53 ,
209- target : ts . ScriptTarget . ES2015 ,
210- } ;
211- expect ( ( ) => util . transpileString ( code , compilerOptions ) ) . toThrowExactError (
212- UnsupportedNonDestructuringLuaIterator ( util . nodeStub )
213- ) ;
159+ ` . expectDiagnosticsToMatchSnapshot ( ) ;
214160} ) ;
215161
216162test ( "forof forwarded lua iterator" , ( ) => {
@@ -231,12 +177,7 @@ test("forof forwarded lua iterator", () => {
231177 for (let a of forward()) { result += a; }
232178 return result;
233179 ` ;
234- const compilerOptions = {
235- luaLibImport : tstl . LuaLibImportKind . Require ,
236- luaTarget : tstl . LuaTarget . Lua53 ,
237- target : ts . ScriptTarget . ES2015 ,
238- } ;
239- const result = util . transpileAndExecute ( code , compilerOptions ) ;
180+ const result = util . transpileAndExecute ( code ) ;
240181 expect ( result ) . toBe ( "abc" ) ;
241182} ) ;
242183
@@ -262,11 +203,6 @@ test("forof forwarded lua iterator with tupleReturn", () => {
262203 for (let [a, b] of forward()) { result += a + b; }
263204 return result;
264205 ` ;
265- const compilerOptions = {
266- luaLibImport : tstl . LuaLibImportKind . Require ,
267- luaTarget : tstl . LuaTarget . Lua53 ,
268- target : ts . ScriptTarget . ES2015 ,
269- } ;
270- const result = util . transpileAndExecute ( code , compilerOptions ) ;
206+ const result = util . transpileAndExecute ( code ) ;
271207 expect ( result ) . toBe ( "0a1b2c" ) ;
272208} ) ;
0 commit comments