@@ -320,7 +320,98 @@ export class LuaLibArrayTests {
320320 Expect ( result ) . toBe ( expected [ 1 ] ) ;
321321 }
322322 }
323+ @TestCase ( "[1, 2, 3]" , [ 3 , 2 , 1 ] )
324+ @TestCase ( "[1, 2, 3, null]" , [ 3 , 2 , 1 ] )
325+ @TestCase ( "[1, 2, 3, 4]" , [ 4 , 3 , 2 , 1 ] )
326+ @TestCase ( "[1]" , [ 1 ] )
327+ @TestCase ( "[]" , [ ] )
328+ @Test ( "array.reverse" )
329+ public arrayReverse ( array : string , expected ) : void {
330+ {
331+ // Transpile
332+ const lua = util . transpileString (
333+ `let testArray = ${ array } ;
334+ let val = testArray.reverse();
335+ return JSONStringify(testArray)` ) ;
336+
337+ // Execute
338+ const result = util . executeLua ( lua ) ;
339+ // Assert
340+ Expect ( result ) . toBe ( JSON . stringify ( expected ) ) ;
341+ }
342+ }
343+ @TestCase ( "[1, 2, 3]" , [ 2 , 3 ] , 1 )
344+ @TestCase ( "[1]" , [ ] , 1 )
345+ @TestCase ( "[]" , [ ] , null )
346+ @Test ( "array.shift" )
347+ public arrayShift ( array : string , expectedArray : number [ ] , expectedValue : number ) : void {
348+ {
349+ // test array mutation
350+ {
351+ // Transpile
352+ const lua = util . transpileString (
353+ `let testArray = ${ array } ;
354+ let val = testArray.shift();
355+ return JSONStringify(testArray)` ) ;
356+
357+ // Execute
358+ const result = util . executeLua ( lua ) ;
359+ // Assert
360+ Expect ( result ) . toBe ( JSON . stringify ( expectedArray ) ) ;
361+ }
362+ // test return value
363+ {
364+ // Transpile
365+ const lua = util . transpileString (
366+ `let testArray = ${ array } ;
367+ let val = testArray.shift();
368+ return val` ) ;
369+
370+ // Execute
371+ const result = util . executeLua ( lua ) ;
372+ // Assert
373+ Expect ( result ) . toBe ( expectedValue ) ;
374+ }
375+ }
376+ }
377+ @TestCase ( "[3, 4, 5]" , [ 1 , 2 ] , [ 1 , 2 , 3 , 4 , 5 ] )
378+ @TestCase ( "[]" , [ ] , [ ] )
379+ @TestCase ( "[1]" , [ ] , [ 1 ] )
380+ @TestCase ( "[]" , [ 1 ] , [ 1 ] )
381+ @Test ( "array.unshift" )
382+ public arrayUnshift ( array : string , toUnshift , expected ) : void {
383+ {
384+ // Transpile
385+ const lua = util . transpileString (
386+ `let testArray = ${ array } ;
387+ testArray.unshift(${ toUnshift } );
388+ return JSONStringify(testArray)` ) ;
389+ // Execute
390+ const result = util . executeLua ( lua ) ;
391+
392+ // Assert
393+ Expect ( result ) . toBe ( JSON . stringify ( expected ) ) ;
394+ }
395+ }
396+ @TestCase ( "[4, 5, 3, 2, 1]" , [ 1 , 2 , 3 , 4 , 5 ] )
397+ @TestCase ( "[1]" , [ 1 ] )
398+ @TestCase ( "[1, null]" , [ 1 ] )
399+ @TestCase ( "[]" , [ ] )
400+ @Test ( "array.sort" )
401+ public arraySort ( array : string , expected ) : void {
402+ {
403+ // Transpile
404+ const lua = util . transpileString (
405+ `let testArray = ${ array } ;
406+ testArray.sort();
407+ return JSONStringify(testArray)` ) ;
323408
409+ // Execute
410+ const result = util . executeLua ( lua ) ;
411+ // Assert
412+ Expect ( result ) . toBe ( JSON . stringify ( expected ) ) ;
413+ }
414+ }
324415 @TestCase ( "true" , "4" , "5" , 4 )
325416 @TestCase ( "false" , "4" , "5" , 5 )
326417 @TestCase ( "3" , "4" , "5" , 4 )
0 commit comments