summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/builtins/Array/Array.of.js
blob: 49b1561d8841de954ac756b984a1c5c46ef4f18a (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 {
    assert(Array.of.length === 0);

    assert(typeof Array.of() === "object");

    var a;

    a = Array.of(5);
    assert(a.length === 1);
    assert(a[0] === 5);

    a = Array.of("5");
    assert(a.length === 1);
    assert(a[0] === "5");

    a = Array.of(Infinity);
    assert(a.length === 1);
    assert(a[0] === Infinity);

    a = Array.of(1, 2, 3);
    assert(a.length === 3);
    assert(a[0] === 1);
    assert(a[1] === 2);
    assert(a[2] === 3);

    a = Array.of([1, 2, 3]);
    assert(a.length === 1);
    assert(a[0][0] === 1);
    assert(a[0][1] === 2);
    assert(a[0][2] === 3);

    let t = [1, 2, 3];
    Object.defineProperty(t, 3, { get() { return 4; } });
    a = Array.of(...t);
    assert(a.length === 4);
    assert(a[0] === 1);
    assert(a[1] === 2);
    assert(a[2] === 3);
    assert(a[3] === 4);

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