rhino/testsrc/doctests/array.dense.doctest
raw| 1 | // This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | |
| 5 | // test various array methods with dense arrays |
| 6 | js> var x = [] |
| 7 | |
| 8 | js> x[10] = 1 |
| 9 | 1 |
| 10 | js> x.length |
| 11 | 11 |
| 12 | js> 0 in x |
| 13 | false |
| 14 | js> x.shift() |
| 15 | js> x.length |
| 16 | 10 |
| 17 | js> 0 in x |
| 18 | false |
| 19 | js> x |
| 20 | ,,,,,,,,,1 |
| 21 | js> x.reverse() |
| 22 | 1,,,,,,,,, |
| 23 | js> x.length |
| 24 | 10 |
| 25 | js> 9 in x |
| 26 | false |
| 27 | js> x.reverse() |
| 28 | ,,,,,,,,,1 |
| 29 | js> x.length |
| 30 | 10 |
| 31 | js> 5 in x |
| 32 | false |
| 33 | js> x.unshift(2) |
| 34 | 11 |
| 35 | js> x |
| 36 | 2,,,,,,,,,,1 |
| 37 | js> 9 in x |
| 38 | false |
| 39 | js> var r = x.splice(3, 4, 3, 4, 5) |
| 40 | js> r |
| 41 | ,,, |
| 42 | js> r.length |
| 43 | 4 |
| 44 | js> 2 in r |
| 45 | false |
| 46 | js> x.length |
| 47 | 10 |
| 48 | js> x |
| 49 | 2,,,3,4,5,,,,1 |
| 50 | js> x[5] |
| 51 | 5 |
| 52 | js> 8 in x |
| 53 | false |
| 54 | js> var s = x.slice(6, 8); |
| 55 | js> s |
| 56 | , |
| 57 | js> s.length |
| 58 | 2 |
| 59 | js> 1 in s |
| 60 | false |
| 61 | js> var y = [] |
| 62 | js> y[9] = 1 |
| 63 | 1 |
| 64 | js> var z = y.concat(x) |
| 65 | js> z |
| 66 | ,,,,,,,,,1,2,,,3,4,5,,,,1 |
| 67 | js> z.length |
| 68 | 20 |
| 69 | js> 2 in z |
| 70 | false |
| 71 | js> 12 in z |
| 72 | false |
| 73 |