js/src/tests/ecma_5/Number/conversion-invalid-precision.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/Number/conversion-invalid-precision.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommonn.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +var BUGNUMBER = 795745;
    1.10 +var summary =
    1.11 +  "Number.prototype.to* should throw a RangeError when passed a bad precision";
    1.12 +
    1.13 +print(BUGNUMBER + ": " + summary);
    1.14 +
    1.15 +/**************
    1.16 + * BEGIN TEST *
    1.17 + **************/
    1.18 +
    1.19 +function test(method, prec)
    1.20 +{
    1.21 +  try
    1.22 +  {
    1.23 +    Number.prototype[method].call(0, prec);
    1.24 +    throw "should have thrown";
    1.25 +  }
    1.26 +  catch (e)
    1.27 +  {
    1.28 +    assertEq(e instanceof RangeError, true,
    1.29 +             "expected RangeError for " + method + " with precision " + prec +
    1.30 +             ", got " + e);
    1.31 +  }
    1.32 +}
    1.33 +
    1.34 +test("toExponential", -32);
    1.35 +test("toFixed", -32);
    1.36 +test("toPrecision", -32);
    1.37 +
    1.38 +test("toExponential", 9999999);
    1.39 +test("toFixed", 9999999);
    1.40 +test("toPrecision", 9999999);
    1.41 +
    1.42 +test("toPrecision", 0);
    1.43 +
    1.44 +/******************************************************************************/
    1.45 +
    1.46 +if (typeof reportCompare === "function")
    1.47 +  reportCompare(true, true);
    1.48 +
    1.49 +print("Tests complete");

mercurial