@@ -21,6 +21,39 @@ export class LuaLibTests
2121 Expect ( result ) . toBe ( JSON . stringify ( expected ) ) ;
2222 }
2323
24+ @TestCase ( [ ] , 3 , - 1 )
25+ @TestCase ( [ 0 , 2 , 4 , 8 ] , 10 , - 1 )
26+ @TestCase ( [ 0 , 2 , 4 , 8 ] , 8 , 3 )
27+ @Test ( "array.findIndex[value]" )
28+ public findIndexByValue ( inp : number [ ] , searchEl : number , expected : number ) : void
29+ {
30+ const result = util . transpileAndExecute (
31+ `let arrTest = ${ JSON . stringify ( inp ) } ;
32+ return JSONStringify(arrTest.findIndex((elem, index) => {
33+ return elem === ${ searchEl } ;
34+ }));`
35+ ) ;
36+
37+ // Assert
38+ Expect ( result ) . toBe ( expected ) ;
39+ }
40+
41+ @TestCase ( [ 0 , 2 , 4 , 8 ] , 3 , 8 )
42+ @TestCase ( [ 0 , 2 , 4 , 8 ] , 1 , 2 )
43+ @Test ( "array.findIndex[index]" )
44+ public findIndexByIndex ( inp : number [ ] , expected : number , value : number ) : void
45+ {
46+ const result = util . transpileAndExecute (
47+ `let arrTest = ${ JSON . stringify ( inp ) } ;
48+ return JSONStringify(arrTest.findIndex((elem, index, arr) => {
49+ return index === ${ expected } && arr[${ expected } ] === ${ value } ;
50+ }));`
51+ ) ;
52+
53+ // Assert
54+ Expect ( result ) . toBe ( expected ) ;
55+ }
56+
2457 @TestCase ( [ ] , "x => x" )
2558 @TestCase ( [ 0 , 1 , 2 , 3 ] , "x => x" )
2659 @TestCase ( [ 0 , 1 , 2 , 3 ] , "x => x*2" )
0 commit comments