summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/update-expressions-basic.js
blob: a097d52e50c65777e7feb641c103ab280ec47b7f (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
load("test-common.js");

try {
    assertThrowsError(() => {
        ++x;
    }, {
        error: ReferenceError,
        message: "'x' is not defined",
    });

    var n = 0;
    assert(++n === 1);
    assert(n === 1);

    var n = 0;
    assert(n++ === 0);
    assert(n === 1);

    var n = 0;
    assert(--n === -1);
    assert(n === -1);

    var n = 0;
    assert(n-- === 0);
    assert(n === -1);

    var a = [];
    assert(a++ === 0);
    assert(a === 1);

    var b = true;
    assert(b-- === 1);
    assert(b === 0);

    var s = "foo";
    assert(isNaN(++s));
    assert(isNaN(s));

    var s = "foo";
    assert(isNaN(s++));
    assert(isNaN(s));

    var s = "foo";
    assert(isNaN(--s));
    assert(isNaN(s));

    var s = "foo";
    assert(isNaN(s--));
    assert(isNaN(s));

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