@@ -27,7 +27,6 @@ export class ExpressionTests {
2727 } ) . toThrowError ( Error , expectedError ) ;
2828 }
2929
30-
3130 @TestCase ( "1+1" , "1+1" )
3231 @TestCase ( "1-1" , "1-1" )
3332 @TestCase ( "1*1" , "1*1" )
@@ -93,7 +92,7 @@ export class ExpressionTests {
9392 @TestCase ( "a>>>=b" , "a=bit.rshift(a,b)" )
9493 @Test ( "Bitop [JIT]" )
9594 public bitOperatorOverrideJIT ( input : string , lua : string ) {
96- Expect ( util . transpileString ( input , { luaTarget : ' JIT' , dontRequireLuaLib : true } ) ) . toBe ( lua ) ;
95+ Expect ( util . transpileString ( input , { luaTarget : " JIT" , dontRequireLuaLib : true } ) ) . toBe ( lua ) ;
9796 }
9897
9998 @TestCase ( "a&b" , "a&b" )
@@ -108,10 +107,9 @@ export class ExpressionTests {
108107 @TestCase ( "a>>>=b" , "a=a>>>b" )
109108 @Test ( "Bitop [5.3]" )
110109 public bitOperatorOverride53 ( input : string , lua : string ) {
111- Expect ( util . transpileString ( input , { luaTarget : ' 5.3' , dontRequireLuaLib : true } ) ) . toBe ( lua ) ;
110+ Expect ( util . transpileString ( input , { luaTarget : " 5.3" , dontRequireLuaLib : true } ) ) . toBe ( lua ) ;
112111 }
113112
114-
115113 @TestCase ( "1+1" , "1+1" )
116114 @TestCase ( "-1+1" , "-1+1" )
117115 @TestCase ( "1*30+4" , "(1*30)+4" )
@@ -130,7 +128,7 @@ export class ExpressionTests {
130128 }
131129
132130 @Test ( "Arrow Function Expression" )
133- public arrowFunctionExpression ( input : string ) {
131+ public arrowFunctionExpression ( ) {
134132 // Transpile
135133 const lua = util . transpileString ( `let add = (a, b) => a+b; return add(1,2);` ) ;
136134
@@ -141,8 +139,31 @@ export class ExpressionTests {
141139 Expect ( result ) . toBe ( 3 ) ;
142140 }
143141
142+ @TestCase ( [ ] )
143+ @TestCase ( [ 5 ] )
144+ @TestCase ( [ 1 , 2 ] )
145+ @Test ( "Arrow Default Values" )
146+ public arrowFunctionDefaultValues ( inp : number [ ] ) {
147+ // Default value is 3 for v1
148+ const v1 = inp . length > 0 ? inp [ 0 ] : 3 ;
149+ // Default value is 4 for v2
150+ const v2 = inp . length > 1 ? inp [ 1 ] : 4 ;
151+
152+ const callArgs = inp . join ( "," ) ;
153+
154+ // Transpile
155+ const lua = util . transpileString ( `let add = (a: number = 3, b: number = 4) => { return a+b; }`
156+ + `return add(${ callArgs } );` ) ;
157+
158+ // Execute
159+ const result = util . executeLua ( lua ) ;
160+
161+ // Assert
162+ Expect ( result ) . toBe ( v1 + v2 ) ;
163+ }
164+
144165 @Test ( "Function Expression" )
145- public functionExpression ( input : string ) {
166+ public functionExpression ( ) {
146167 // Transpile
147168 const lua = util . transpileString ( `let add = function(a, b) {return a+b}; return add(1,2);` ) ;
148169
@@ -152,4 +173,27 @@ export class ExpressionTests {
152173 // Assert
153174 Expect ( result ) . toBe ( 3 ) ;
154175 }
176+
177+ @TestCase ( [ ] , 7 )
178+ @TestCase ( [ 5 ] , 9 )
179+ @TestCase ( [ 1 , 2 ] , 3 )
180+ @Test ( "Arrow Default Values" )
181+ public functionExpressionDefaultValues ( inp : number [ ] ) {
182+ // Default value is 3 for v1
183+ const v1 = inp . length > 0 ? inp [ 0 ] : 3 ;
184+ // Default value is 4 for v2
185+ const v2 = inp . length > 1 ? inp [ 1 ] : 4 ;
186+
187+ const callArgs = inp . join ( "," ) ;
188+
189+ // Transpile
190+ const lua = util . transpileString ( `let add = function(a: number = 3, b: number = 4) { return a+b; }`
191+ + `return add(${ callArgs } );` ) ;
192+
193+ // Execute
194+ const result = util . executeLua ( lua ) ;
195+
196+ // Assert
197+ Expect ( result ) . toBe ( v1 + v2 ) ;
198+ }
155199}
0 commit comments