@@ -204,20 +204,26 @@ export class LuaLibArrayTests {
204204 @TestCase ( [ ] , "test1" )
205205 @TestCase ( [ "test1" ] , "test1" )
206206 @TestCase ( [ "test1" , "test2" ] , "test2" )
207+ @TestCase ( [ "test1" , "test2" , "test3" ] , "test3" , 1 )
208+ @TestCase ( [ "test1" , "test2" , "test3" ] , "test1" , 2 )
209+ @TestCase ( [ "test1" , "test2" , "test3" ] , "test1" , - 2 )
210+ @TestCase ( [ "test1" , "test2" , "test3" ] , "test1" , 12 )
207211 @Test ( "array.indexOf" )
208- public indexOf ( inp : string [ ] , element : string ) {
209- // Transpile
210- const lua = util . transpileString (
211- `return ${ JSON . stringify ( inp ) } .indexOf("${ element } "))`
212+ public indexOf ( inp : string [ ] , element : string , fromIndex ?: number ) {
213+ let str = `return ${ JSON . stringify ( inp ) } .indexOf("${ element } "))` ;
214+ if ( fromIndex ) {
215+ str = `return ${ JSON . stringify ( inp ) } .indexOf("${ element } ", ${ fromIndex } ))` ;
216+ }
212217
213- ) ;
218+ // Transpile
219+ const lua = util . transpileString ( str ) ;
214220
215221 // Execute
216222 const result = util . executeLua ( lua ) ;
217223
218224 // Assert
219- // Acount for lua indexing (-1)
220- Expect ( result ) . toBe ( inp . indexOf ( element ) ) ;
225+ // Account for lua indexing (-1)
226+ Expect ( result ) . toBe ( inp . indexOf ( element , fromIndex ) ) ;
221227 }
222228
223229 @TestCase ( [ 1 , 2 , 3 ] , 3 )
0 commit comments