1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: Testing Number.prototype.toExponential(fractionDigits)
43 * See EMCA 262 Edition 3 Section 15.7.4.6
45 * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
48 //-----------------------------------------------------------------------------
50 var BUGNUMBER = '(none)';
51 var summary = 'Testing Number.prototype.toExponential(fractionDigits)';
52 var cnIsRangeError = 'instanceof RangeError';
53 var cnNotRangeError = 'NOT instanceof RangeError';
54 var cnNoErrorCaught = 'NO ERROR CAUGHT...';
58 var actualvalues = [];
60 var expectedvalues = [];
61 var testNum = 77.1234;
64 status = 'Section A of test: no error intended!';
65 actual = testNum.toExponential(4);
69 status = 'Section B of test: Infinity.toExponential() with out-of-range fractionDigits';
70 actual = Number.POSITIVE_INFINITY.toExponential(-3);
74 status = 'Section C of test: -Infinity.toExponential() with out-of-range fractionDigits';
75 actual = Number.NEGATIVE_INFINITY.toExponential(-3);
79 status = 'Section D of test: NaN.toExponential() with out-of-range fractionDigits';
80 actual = Number.NaN.toExponential(-3);
85 /////////////////////////// OOPS.... ///////////////////////////////
86 /*************************************************************************
87 * 15.7.4.6 Number.prototype.toExponential(fractionDigits)
89 * An implementation is permitted to extend the behaviour of toExponential
90 * for values of fractionDigits less than 0 or greater than 20. In this
91 * case toExponential would not necessarily throw RangeError for such values.
93 status = 'Section B of test: expect RangeError because fractionDigits < 0';
94 actual = catchError('testNum.toExponential(-4)');
95 expect = cnIsRangeError;
98 status = 'Section C of test: expect RangeError because fractionDigits > 20 ';
99 actual = catchError('testNum.toExponential(21)');
100 expect = cnIsRangeError;
102 *************************************************************************/
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
111 function captureThis()
113 statusitems[UBound] = status;
114 actualvalues[UBound] = actual;
115 expectedvalues[UBound] = expect;
123 printBugNumber(BUGNUMBER);
124 printStatus (summary);
126 for (var i = 0; i < UBound; i++)
128 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
135 function catchError(sEval)
138 catch(e) {return isRangeError(e);}
139 return cnNoErrorCaught;
143 function isRangeError(obj)
145 if (obj instanceof RangeError)
146 return cnIsRangeError;
147 return cnNotRangeError;