summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/string-int32-arith.js
blob: 8f39d3e12449458927108c46c33e4f74030739ae (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
function test(zero, one) {
    assertEq(10 - zero, 10);
    assertEq(10 - one, 9);
    assertEq(zero - 0, 0);
    assertEq(one - 1, 0);

    assertEq(10 * zero, 0);
    assertEq(zero * 10, 0);
    assertEq(10 * one, 10);
    assertEq(one * 10, 10);

    assertEq(10 / one, 10);
    assertEq(one / 1, 1);
    assertEq(10 % one, 0);
    assertEq(one % 1, 0);

    assertEq(10 ** one, 10);
    assertEq(one ** 4, 1);

    assertEq(10 & zero, 0);
    assertEq(zero & 10, 0);
    assertEq(10 & one, 0);
    assertEq(one & 10, 0);

    assertEq(10 | zero, 10);
    assertEq(zero | 10, 10);
    assertEq(10 | one, 11);
    assertEq(one | 10, 11);

    assertEq(10 ^ zero, 10);
    assertEq(zero ^ 10, 10);
    assertEq(10 ^ one, 11);
    assertEq(one ^ 10, 11);

    assertEq(10 << zero, 10);
    assertEq(zero << 10, 0);
    assertEq(10 << one, 20);
    assertEq(one << 10, 1024);

    assertEq(10 >> zero, 10);
    assertEq(zero >> 10, 0);
    assertEq(10 >> one, 5);
    assertEq(one >> 10, 0);

    assertEq(10 >>> zero, 10);
    assertEq(zero >>> 10, 0);
    assertEq(10 >>> one, 5);
    assertEq(one >>> 10, 0);
}

for (var i = 0; i < 10; i++) {
    test(0, 1);
    test('0', '1');
    test('0x0', '0x1');
    test('0.0', '1.0');
}