summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/pipeline/precedence.js
blob: 0ef6ff7281931c596519485a84ef5515b17b7a17 (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
47
48
49
50
51
52
53
54
55
56
const BUGNUMBER = 1405943;
const summary = "Implement pipeline operator (operator precedence)";

print(BUGNUMBER + ": " + summary);

if (hasPipeline()) {
    // Operator precedence
    eval(`
    const double = (n) => n * 2;
    const increment = (n) => n + 1;
    const getType = (v) => typeof v;
    const toString = (v) => v.toString();
    let a = 8;
    assertEq(10 |> double |> increment |> double, 42);
    assertEq(++ a |> double, 18);
    assertEq(typeof 42 |> toString, "number");
    assertEq(! true |> toString, "false");
    assertEq(delete 42 |> toString, "true");
    assertEq(10 ** 2 |> double, 200);
    assertEq(10 * 2 |> increment, 21);
    assertEq(5 + 5 |> double, 20);
    assertEq(1 << 4 |> double, 32);
    assertEq(0 < 1 |> toString, "true");
    assertEq("a" in {} |> toString, "false");
    assertEq(10 instanceof String |> toString, "false");
    assertEq(10 == 10 |> toString, "true");
    assertEq(0b0101 & 0b1101 |> increment, 0b0110);
    assertEq(false && true |> toString, "false");
    assertEq(0 |> double ? toString : null, null);
    assertEq(true ? 20 |> toString : 10, '20');
    assertEq(true ? 10 : 20 |> toString, 10);
    a = 10 |> toString;
    assertEq(a, "10");
    a = 10;
    a += 2 |> increment;
    assertEq(a, 13);

    // Right-side association
    a = toString;
    assertThrowsInstanceOf(() => "42" |> parseInt ** 2, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt * 1, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt + 0, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt << 1, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt < 0, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt in {}, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt instanceof String, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt == 255, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt & 0b1111, TypeError);
    assertThrowsInstanceOf(() => "42" |> parseInt && true, TypeError);
    assertThrowsInstanceOf(() => Function('"42" |> a = parseInt'), ReferenceError);
    assertThrowsInstanceOf(() => Function('"42" |> a += parseInt'), ReferenceError);
    `);
}

if (typeof reportCompare === "function")
    reportCompare(0, 0);