summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/array-basic.js
blob: b39bcda1342b2a73fd0911f38c76354ee4e5dc14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
load("test-common.js");

try {
    var a = [1, 2, 3];

    assert(typeof a === "object");
    assert(a.length === 3);
    assert(a[0] === 1);
    assert(a[1] === 2);
    assert(a[2] === 3);

    a[1] = 5;
    assert(a[1] === 5);
    assert(a.length === 3);

    a.push(7);
    assert(a[3] === 7);
    assert(a.length === 4);

    a = [,];
    assert(a.length === 1);
    assert(a.toString() === "");
    assert(a[0] === undefined);

    a = [,,,,];
    assert(a.length === 4);
    assert(a.toString() === ",,,");
    assert(a[0] === undefined);
    assert(a[1] === undefined);
    assert(a[2] === undefined);
    assert(a[3] === undefined);

    a = [1,,2,,,3,];
    assert(a.length === 6);
    assert(a.toString() === "1,,2,,,3");
    assert(a[0] === 1);
    assert(a[1] === undefined);
    assert(a[2] === 2);
    assert(a[3] === undefined);
    assert(a[4] === undefined);
    assert(a[5] === 3);

    console.log("PASS");
} catch (e) {
    console.log("FAIL: " + e);
}