ap | 6449aac | 2006-08-21 17:43:55 +0000 | [diff] [blame] | 1 | description( |
| 2 | 'This test checks lastIndexOf for various values in an array' |
| 3 | ); |
| 4 | |
| 5 | |
| 6 | var testArray = [2, 5, 9, 2]; |
| 7 | var lastIndex = 0; |
| 8 | |
| 9 | lastIndex = testArray.lastIndexOf(2,-500); |
| 10 | shouldBe('lastIndex', '-1'); |
| 11 | lastIndex = testArray.lastIndexOf(9,500); |
| 12 | shouldBe('lastIndex', '2'); |
| 13 | lastIndex = testArray.lastIndexOf(2); |
| 14 | shouldBe('lastIndex', '3'); |
| 15 | lastIndex = testArray.lastIndexOf(7); |
| 16 | shouldBe('lastIndex', '-1'); |
| 17 | lastIndex = testArray.lastIndexOf(2, 3); |
| 18 | shouldBe('lastIndex', '3'); |
| 19 | lastIndex = testArray.lastIndexOf(2, 2); |
| 20 | shouldBe('lastIndex', '0'); |
| 21 | lastIndex = testArray.lastIndexOf(2, -2); |
| 22 | shouldBe('lastIndex', '0'); |
| 23 | lastIndex = testArray.lastIndexOf(2, -1); |
| 24 | shouldBe('lastIndex', '3'); |
| 25 | |
dsmith | ebd6d4e | 2007-03-29 06:20:38 +0000 | [diff] [blame] | 26 | delete testArray[1]; |
| 27 | |
| 28 | lastIndex = testArray.lastIndexOf(undefined); |
| 29 | shouldBe('lastIndex', '-1'); |
| 30 | |
| 31 | delete testArray[3]; |
| 32 | |
| 33 | lastIndex = testArray.lastIndexOf(undefined); |
| 34 | shouldBe('lastIndex', '-1'); |
| 35 | |
| 36 | testArray = new Array(20); |
| 37 | |
| 38 | lastIndex = testArray.lastIndexOf(undefined); |
| 39 | shouldBe('lastIndex', '-1'); |
| 40 | |
| 41 | testArray[19] = undefined; |
| 42 | |
| 43 | lastIndex = testArray.lastIndexOf(undefined); |
| 44 | shouldBe('lastIndex', '19'); |
| 45 | |
| 46 | lastIndex = testArray.lastIndexOf(undefined, 18); |
| 47 | shouldBe('lastIndex', '-1'); |
| 48 | |
| 49 | delete testArray[19]; |
| 50 | |
| 51 | lastIndex = testArray.lastIndexOf(undefined); |
| 52 | shouldBe('lastIndex', '-1'); |