michael@0: // |reftest| fails michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 2001-07-15 michael@0: * michael@0: * SUMMARY: Testing Number.prototype.toExponential(fractionDigits) michael@0: * See EMCA 262 Edition 3 Section 15.7.4.6 michael@0: * michael@0: * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551 michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = '(none)'; michael@0: var summary = 'Testing Number.prototype.toExponential(fractionDigits)'; michael@0: var cnIsRangeError = 'instanceof RangeError'; michael@0: var cnNotRangeError = 'NOT instanceof RangeError'; michael@0: var cnNoErrorCaught = 'NO ERROR CAUGHT...'; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: var testNum = 77.1234; michael@0: michael@0: michael@0: status = 'Section A of test: no error intended!'; michael@0: actual = testNum.toExponential(4); michael@0: expect = '7.7123e+1'; michael@0: captureThis(); michael@0: michael@0: status = 'Section B of test: Infinity.toExponential() with out-of-range fractionDigits'; michael@0: actual = Number.POSITIVE_INFINITY.toExponential(-3); michael@0: expect = 'Infinity'; michael@0: captureThis(); michael@0: michael@0: status = 'Section C of test: -Infinity.toExponential() with out-of-range fractionDigits'; michael@0: actual = Number.NEGATIVE_INFINITY.toExponential(-3); michael@0: expect = '-Infinity'; michael@0: captureThis(); michael@0: michael@0: status = 'Section D of test: NaN.toExponential() with out-of-range fractionDigits'; michael@0: actual = Number.NaN.toExponential(-3); michael@0: expect = 'NaN'; michael@0: captureThis(); michael@0: michael@0: michael@0: /////////////////////////// OOPS.... /////////////////////////////// michael@0: /************************************************************************* michael@0: * 15.7.4.6 Number.prototype.toExponential(fractionDigits) michael@0: * michael@0: * An implementation is permitted to extend the behaviour of toExponential michael@0: * for values of fractionDigits less than 0 or greater than 20. In this michael@0: * case toExponential would not necessarily throw RangeError for such values. michael@0: michael@0: status = 'Section B of test: expect RangeError because fractionDigits < 0'; michael@0: actual = catchError('testNum.toExponential(-4)'); michael@0: expect = cnIsRangeError; michael@0: captureThis(); michael@0: michael@0: status = 'Section C of test: expect RangeError because fractionDigits > 20 '; michael@0: actual = catchError('testNum.toExponential(21)'); michael@0: expect = cnIsRangeError; michael@0: captureThis(); michael@0: *************************************************************************/ michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: function captureThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (var i = 0; i < UBound; i++) michael@0: { michael@0: reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: } michael@0: michael@0: michael@0: function catchError(sEval) michael@0: { michael@0: try {eval(sEval);} michael@0: catch(e) {return isRangeError(e);} michael@0: return cnNoErrorCaught; michael@0: } michael@0: michael@0: michael@0: function isRangeError(obj) michael@0: { michael@0: if (obj instanceof RangeError) michael@0: return cnIsRangeError; michael@0: return cnNotRangeError; michael@0: }