1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Number/15.7.4.6-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 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.toExponential(fractionDigits) 1.14 + * See EMCA 262 Edition 3 Section 15.7.4.6 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.toExponential(fractionDigits)'; 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 = 77.1234; 1.33 + 1.34 + 1.35 +status = 'Section A of test: no error intended!'; 1.36 +actual = testNum.toExponential(4); 1.37 +expect = '7.7123e+1'; 1.38 +captureThis(); 1.39 + 1.40 +status = 'Section B of test: Infinity.toExponential() with out-of-range fractionDigits'; 1.41 +actual = Number.POSITIVE_INFINITY.toExponential(-3); 1.42 +expect = 'Infinity'; 1.43 +captureThis(); 1.44 + 1.45 +status = 'Section C of test: -Infinity.toExponential() with out-of-range fractionDigits'; 1.46 +actual = Number.NEGATIVE_INFINITY.toExponential(-3); 1.47 +expect = '-Infinity'; 1.48 +captureThis(); 1.49 + 1.50 +status = 'Section D of test: NaN.toExponential() with out-of-range fractionDigits'; 1.51 +actual = Number.NaN.toExponential(-3); 1.52 +expect = 'NaN'; 1.53 +captureThis(); 1.54 + 1.55 + 1.56 +/////////////////////////// OOPS.... /////////////////////////////// 1.57 +/************************************************************************* 1.58 + * 15.7.4.6 Number.prototype.toExponential(fractionDigits) 1.59 + * 1.60 + * An implementation is permitted to extend the behaviour of toExponential 1.61 + * for values of fractionDigits less than 0 or greater than 20. In this 1.62 + * case toExponential would not necessarily throw RangeError for such values. 1.63 + 1.64 +status = 'Section B of test: expect RangeError because fractionDigits < 0'; 1.65 +actual = catchError('testNum.toExponential(-4)'); 1.66 +expect = cnIsRangeError; 1.67 +captureThis(); 1.68 + 1.69 +status = 'Section C of test: expect RangeError because fractionDigits > 20 '; 1.70 +actual = catchError('testNum.toExponential(21)'); 1.71 +expect = cnIsRangeError; 1.72 +captureThis(); 1.73 +*************************************************************************/ 1.74 + 1.75 + 1.76 + 1.77 +//----------------------------------------------------------------------------- 1.78 +test(); 1.79 +//----------------------------------------------------------------------------- 1.80 + 1.81 + 1.82 +function captureThis() 1.83 +{ 1.84 + statusitems[UBound] = status; 1.85 + actualvalues[UBound] = actual; 1.86 + expectedvalues[UBound] = expect; 1.87 + UBound++; 1.88 +} 1.89 + 1.90 + 1.91 +function test() 1.92 +{ 1.93 + enterFunc ('test'); 1.94 + printBugNumber(BUGNUMBER); 1.95 + printStatus (summary); 1.96 + 1.97 + for (var i = 0; i < UBound; i++) 1.98 + { 1.99 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.100 + } 1.101 + 1.102 + exitFunc ('test'); 1.103 +} 1.104 + 1.105 + 1.106 +function catchError(sEval) 1.107 +{ 1.108 + try {eval(sEval);} 1.109 + catch(e) {return isRangeError(e);} 1.110 + return cnNoErrorCaught; 1.111 +} 1.112 + 1.113 + 1.114 +function isRangeError(obj) 1.115 +{ 1.116 + if (obj instanceof RangeError) 1.117 + return cnIsRangeError; 1.118 + return cnNotRangeError; 1.119 +}