js/src/tests/ecma_3/Number/15.7.4.7-1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // |reftest| fails
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /*
     8  * Date: 2001-07-15
     9  *
    10  * SUMMARY: Testing Number.prototype.toPrecision(precision)
    11  * See EMCA 262 Edition 3 Section 15.7.4.7
    12  *
    13  * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
    14  *
    15  */
    16 //-----------------------------------------------------------------------------
    17 var UBound = 0;
    18 var BUGNUMBER = '(none)';
    19 var summary = 'Testing Number.prototype.toPrecision(precision)';
    20 var cnIsRangeError = 'instanceof RangeError';
    21 var cnNotRangeError = 'NOT instanceof RangeError';
    22 var cnNoErrorCaught = 'NO ERROR CAUGHT...';
    23 var status = '';
    24 var statusitems = [];
    25 var actual = '';
    26 var actualvalues = [];
    27 var expect= '';
    28 var expectedvalues = [];
    29 var testNum = 5.123456;
    32 status = 'Section A of test: no error intended!';
    33 actual = testNum.toPrecision(4);
    34 expect = '5.123';
    35 captureThis();
    37 status = 'Section B of test: Infinity.toPrecision() with out-of-range fractionDigits';
    38 actual = Number.POSITIVE_INFINITY.toPrecision(-3);
    39 expect = 'Infinity';
    40 captureThis();
    42 status = 'Section C of test: -Infinity.toPrecision() with out-of-range fractionDigits';
    43 actual = Number.NEGATIVE_INFINITY.toPrecision(-3);
    44 expect = '-Infinity';
    45 captureThis();
    47 status = 'Section D of test: NaN.toPrecision() with out-of-range fractionDigits';
    48 actual = Number.NaN.toPrecision(-3);
    49 expect = 'NaN';
    50 captureThis();
    53 ///////////////////////////    OOPS....    ///////////////////////////////
    54 /*************************************************************************
    55  * 15.7.4.7 Number.prototype.toPrecision(precision)
    56  *
    57  * An implementation is permitted to extend the behaviour of toPrecision
    58  * for values of precision less than 1 or greater than 21. In this
    59  * case toPrecision would not necessarily throw RangeError for such values.
    61 status = 'Section B of test: expect RangeError because precision < 1';
    62 actual = catchError('testNum.toPrecision(0)');
    63 expect = cnIsRangeError;
    64 captureThis();
    66 status = 'Section C of test: expect RangeError because precision < 1';
    67 actual = catchError('testNum.toPrecision(-4)');
    68 expect = cnIsRangeError;
    69 captureThis();
    71 status = 'Section D of test: expect RangeError because precision > 21 ';
    72 actual = catchError('testNum.toPrecision(22)');
    73 expect = cnIsRangeError;
    74 captureThis();
    75 *************************************************************************/
    79 //-----------------------------------------------------------------------------
    80 test();
    81 //-----------------------------------------------------------------------------
    84 function captureThis()
    85 {
    86   statusitems[UBound] = status;
    87   actualvalues[UBound] = actual;
    88   expectedvalues[UBound] = expect;
    89   UBound++;
    90 }
    93 function test()
    94 {
    95   enterFunc ('test');
    96   printBugNumber(BUGNUMBER);
    97   printStatus (summary);
    99   for (var i = 0; i < UBound; i++)
   100   {
   101     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   102   }
   104   exitFunc ('test');
   105 }
   108 function catchError(sEval)
   109 {
   110   try {eval(sEval);}
   111   catch(e) {return isRangeError(e);}
   112   return cnNoErrorCaught;
   113 }
   116 function isRangeError(obj)
   117 {
   118   if (obj instanceof RangeError)
   119     return cnIsRangeError;
   120   return cnNotRangeError;
   121 }

mercurial