11import * as util from "../../util" ;
22
3- test . each ( [ { } , { noHoisting : true } ] ) ( "@vararg" , compilerOptions => {
4- const code = `
5- /** @vararg */ type LuaVarArg<A extends unknown[]> = A & { __luaVarArg?: never };
3+ const varargDeclaration = `
4+ /** @vararg */
5+ type LuaVarArg<A extends unknown[]> = A & { __luaVararg?: never };
6+ ` ;
7+
8+ test ( "@vararg" , ( ) => {
9+ util . testFunction `
10+ ${ varargDeclaration }
611 function foo(a: unknown, ...b: LuaVarArg<unknown[]>) {
712 const c = [...b];
813 return c.join("");
@@ -11,45 +16,30 @@ test.each([{}, { noHoisting: true }])("@vararg", compilerOptions => {
1116 return foo(a, ...b);
1217 }
1318 return bar("A", "B", "C", "D");
14- ` ;
15-
16- const lua = util . transpileString ( code , compilerOptions ) ;
17- expect ( lua ) . not . toMatch ( "b = ({...})" ) ;
18- expect ( lua ) . not . toMatch ( "unpack" ) ;
19- expect ( util . transpileAndExecute ( code , compilerOptions ) ) . toBe ( "BCD" ) ;
19+ `
20+ . tap ( builder => expect ( builder . getMainLuaCodeChunk ( ) ) . not . toMatch ( "b = " ) )
21+ . tap ( builder => expect ( builder . getMainLuaCodeChunk ( ) ) . not . toMatch ( "unpack" ) )
22+ . expectToMatchJsResult ( ) ;
2023} ) ;
2124
22- test . each ( [ { } , { noHoisting : true } ] ) ( "@vararg array access" , compilerOptions => {
23- const code = `
24- /** @vararg */ type LuaVarArg<A extends unknown[]> = A & { __luaVarArg?: never };
25+ test ( "@vararg array access" , ( ) => {
26+ util . testFunction `
27+ ${ varargDeclaration }
2528 function foo(a: unknown, ...b: LuaVarArg<unknown[]>) {
2629 const c = [...b];
2730 return c.join("") + b[0];
2831 }
2932 return foo("A", "B", "C", "D");
30- ` ;
31-
32- expect ( util . transpileAndExecute ( code , compilerOptions ) ) . toBe ( "BCDB" ) ;
33+ ` . expectToMatchJsResult ( ) ;
3334} ) ;
3435
35- test . each ( [ { } , { noHoisting : true } ] ) ( "@vararg global" , compilerOptions => {
36- const code = `
37- /** @vararg */ type LuaVarArg<A extends unknown[]> = A & { __luaVarArg?: never };
36+ test ( "@vararg global" , ( ) => {
37+ util . testModule `
38+ ${ varargDeclaration }
3839 declare const arg: LuaVarArg<string[]>;
39- const arr = [...arg];
40- const result = arr.join("");
41- ` ;
42-
43- const luaBody = util . transpileString ( code , compilerOptions , false ) ;
44- expect ( luaBody ) . not . toMatch ( "unpack" ) ;
45-
46- const lua = `
47- function test(...)
48- ${ luaBody }
49- return result
50- end
51- return test("A", "B", "C", "D")
52- ` ;
53-
54- expect ( util . executeLua ( lua ) ) . toBe ( "ABCD" ) ;
40+ export const result = [...arg].join("");
41+ `
42+ . setLuaFactory ( code => `return (function(...) ${ code } end)("A", "B", "C", "D")` )
43+ . tap ( builder => expect ( builder . getMainLuaCodeChunk ( ) ) . not . toMatch ( "unpack" ) )
44+ . expectToEqual ( { result : "ABCD" } ) ;
5545} ) ;
0 commit comments