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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Number/15.7.4.7-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +// |reftest| fails
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 + * Date: 2001-07-15
    1.12 + *
    1.13 + * SUMMARY: Testing Number.prototype.toPrecision(precision)
    1.14 + * See EMCA 262 Edition 3 Section 15.7.4.7
    1.15 + *
    1.16 + * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
    1.17 + *
    1.18 + */
    1.19 +//-----------------------------------------------------------------------------
    1.20 +var UBound = 0;
    1.21 +var BUGNUMBER = '(none)';
    1.22 +var summary = 'Testing Number.prototype.toPrecision(precision)';
    1.23 +var cnIsRangeError = 'instanceof RangeError';
    1.24 +var cnNotRangeError = 'NOT instanceof RangeError';
    1.25 +var cnNoErrorCaught = 'NO ERROR CAUGHT...';
    1.26 +var status = '';
    1.27 +var statusitems = [];
    1.28 +var actual = '';
    1.29 +var actualvalues = [];
    1.30 +var expect= '';
    1.31 +var expectedvalues = [];
    1.32 +var testNum = 5.123456;
    1.33 +
    1.34 +
    1.35 +status = 'Section A of test: no error intended!';
    1.36 +actual = testNum.toPrecision(4);
    1.37 +expect = '5.123';
    1.38 +captureThis();
    1.39 +
    1.40 +status = 'Section B of test: Infinity.toPrecision() with out-of-range fractionDigits';
    1.41 +actual = Number.POSITIVE_INFINITY.toPrecision(-3);
    1.42 +expect = 'Infinity';
    1.43 +captureThis();
    1.44 +
    1.45 +status = 'Section C of test: -Infinity.toPrecision() with out-of-range fractionDigits';
    1.46 +actual = Number.NEGATIVE_INFINITY.toPrecision(-3);
    1.47 +expect = '-Infinity';
    1.48 +captureThis();
    1.49 +
    1.50 +status = 'Section D of test: NaN.toPrecision() with out-of-range fractionDigits';
    1.51 +actual = Number.NaN.toPrecision(-3);
    1.52 +expect = 'NaN';
    1.53 +captureThis();
    1.54 +
    1.55 +
    1.56 +///////////////////////////    OOPS....    ///////////////////////////////
    1.57 +/*************************************************************************
    1.58 + * 15.7.4.7 Number.prototype.toPrecision(precision)
    1.59 + *
    1.60 + * An implementation is permitted to extend the behaviour of toPrecision
    1.61 + * for values of precision less than 1 or greater than 21. In this
    1.62 + * case toPrecision would not necessarily throw RangeError for such values.
    1.63 +
    1.64 +status = 'Section B of test: expect RangeError because precision < 1';
    1.65 +actual = catchError('testNum.toPrecision(0)');
    1.66 +expect = cnIsRangeError;
    1.67 +captureThis();
    1.68 +
    1.69 +status = 'Section C of test: expect RangeError because precision < 1';
    1.70 +actual = catchError('testNum.toPrecision(-4)');
    1.71 +expect = cnIsRangeError;
    1.72 +captureThis();
    1.73 +
    1.74 +status = 'Section D of test: expect RangeError because precision > 21 ';
    1.75 +actual = catchError('testNum.toPrecision(22)');
    1.76 +expect = cnIsRangeError;
    1.77 +captureThis();
    1.78 +*************************************************************************/
    1.79 +
    1.80 +
    1.81 +
    1.82 +//-----------------------------------------------------------------------------
    1.83 +test();
    1.84 +//-----------------------------------------------------------------------------
    1.85 +
    1.86 +
    1.87 +function captureThis()
    1.88 +{
    1.89 +  statusitems[UBound] = status;
    1.90 +  actualvalues[UBound] = actual;
    1.91 +  expectedvalues[UBound] = expect;
    1.92 +  UBound++;
    1.93 +}
    1.94 +
    1.95 +
    1.96 +function test()
    1.97 +{
    1.98 +  enterFunc ('test');
    1.99 +  printBugNumber(BUGNUMBER);
   1.100 +  printStatus (summary);
   1.101 +
   1.102 +  for (var i = 0; i < UBound; i++)
   1.103 +  {
   1.104 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.105 +  }
   1.106 +
   1.107 +  exitFunc ('test');
   1.108 +}
   1.109 +
   1.110 +
   1.111 +function catchError(sEval)
   1.112 +{
   1.113 +  try {eval(sEval);}
   1.114 +  catch(e) {return isRangeError(e);}
   1.115 +  return cnNoErrorCaught;
   1.116 +}
   1.117 +
   1.118 +
   1.119 +function isRangeError(obj)
   1.120 +{
   1.121 +  if (obj instanceof RangeError)
   1.122 +    return cnIsRangeError;
   1.123 +  return cnNotRangeError;
   1.124 +}

mercurial