js/src/jit-test/tests/basic/testParseInt.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/testParseInt.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +function testInt(n, result) {
    1.10 +    var x = 0;
    1.11 +    for (var i = 0; i < 15; i++) {
    1.12 +        assertEq(parseInt(n, 10), result);
    1.13 +        assertEq(parseInt(n, 0), result);
    1.14 +        assertEq(parseInt(n), result);
    1.15 +        assertEq(parseInt(n, x), result);
    1.16 +
    1.17 +        if (x % 2 == 0)
    1.18 +            x = 10;
    1.19 +        else
    1.20 +            x = 0;
    1.21 +    }
    1.22 +}
    1.23 +
    1.24 +function testDouble(n, result) {
    1.25 +    var x = 0;
    1.26 +    for (var i = 0; i < 15; i++) {
    1.27 +        assertEq(parseInt(n, 10), result);
    1.28 +        assertEq(parseInt(n, 0), result);
    1.29 +        assertEq(parseInt(n), result);
    1.30 +        assertEq(parseInt(n, x), result);
    1.31 +
    1.32 +        if (x % 2 == 0)
    1.33 +            x = 10;
    1.34 +        else
    1.35 +            x = 0;
    1.36 +    }
    1.37 +}
    1.38 +
    1.39 +testInt(2147483647, 2147483647);
    1.40 +testInt(-2147483648, -2147483648);
    1.41 +testInt(17, 17);
    1.42 +testInt(-1, -1);
    1.43 +testInt(0, 0);
    1.44 +
    1.45 +testDouble(1e21, 1);
    1.46 +testDouble(-5.7, -5);
    1.47 +testDouble(1.7, 1);
    1.48 +testDouble(1.0e-6, 0);
    1.49 +testDouble(1.0e-7, 1);
    1.50 +testDouble(NaN, NaN);
    1.51 +testDouble(1e20, 1e20);

mercurial