Debian Codegraph @

rhino/testsrc/tests/ecma_3/Number/15.7.4.5-1.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 * Date: 2001-07-15
8 *
9 * SUMMARY: Testing Number.prototype.toFixed(fractionDigits)
10 * See EMCA 262 Edition 3 Section 15.7.4.5
11 *
12 * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
13 *
14 */
15 //-----------------------------------------------------------------------------
16 var gTestfile = '15.7.4.5-1.js';
17 var UBound = 0;
18 var BUGNUMBER = '(none)';
19 var summary = 'Testing Number.prototype.toFixed(fractionDigits)';
20 var cnIsRangeError = 'instanceof RangeError';
21 var cnNotRangeError = 'NOT instanceof RangeError';
22 var cnNoErrorCaught = 'NO ERROR CAUGHT...';
23 var status = '';
24 var statusitems = [];
25 var actual = '';
26 var actualvalues = [];
27 var expect= '';
28 var expectedvalues = [];
29 var testNum = 234.2040506;
30
31
32 status = 'Section A of test: no error intended!';
33 actual = testNum.toFixed(4);
34 expect = '234.2041';
35 captureThis();
36
37
38 /////////////////////////// OOPS.... ///////////////////////////////
39 /*************************************************************************
40 * 15.7.4.5 Number.prototype.toFixed(fractionDigits)
41 *
42 * An implementation is permitted to extend the behaviour of toFixed
43 * for values of fractionDigits less than 0 or greater than 20. In this
44 * case toFixed would not necessarily throw RangeError for such values.
45
46 status = 'Section B of test: expect RangeError because fractionDigits < 0';
47 actual = catchError('testNum.toFixed(-4)');
48 expect = cnIsRangeError;
49 captureThis();
50
51 status = 'Section C of test: expect RangeError because fractionDigits > 20 ';
52 actual = catchError('testNum.toFixed(21)');
53 expect = cnIsRangeError;
54 captureThis();
55 *************************************************************************/
56
57
58 status = 'Section D of test: no error intended!';
59 actual = 0.00001.toFixed(2);
60 expect = '0.00';
61 captureThis();
62
63 status = 'Section E of test: no error intended!';
64 actual = 0.000000000000000000001.toFixed(20);
65 expect = '0.00000000000000000000';
66 captureThis();
67
68
69
70 //-----------------------------------------------------------------------------
71 test();
72 //-----------------------------------------------------------------------------
73
74
75 function captureThis()
76 {
77 statusitems[UBound] = status;
78 actualvalues[UBound] = actual;
79 expectedvalues[UBound] = expect;
80 UBound++;
81 }
82
83
84 function test()
85 {
86 enterFunc ('test');
87 printBugNumber(BUGNUMBER);
88 printStatus (summary);
89
90 for (var i = 0; i < UBound; i++)
91 {
92 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
93 }
94
95 exitFunc ('test');
96 }
97
98
99 function catchError(sEval)
100 {
101 try {eval(sEval);}
102 catch(e) {return isRangeError(e);}
103 return cnNoErrorCaught;
104 }
105
106
107 function isRangeError(obj)
108 {
109 if (obj instanceof RangeError)
110 return cnIsRangeError;
111 return cnNotRangeError;
112 }