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

mercurial