]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/GlobalObject/15.1.2.3-2.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.1.2.3-2.js
24 ECMA Section: 15.1.2.3 Function properties of the global object:
27 Description: The parseFloat function produces a number value dictated
28 by the interpretation of the contents of the string
29 argument defined as a decimal literal.
31 When the parseFloat function is called, the following
34 1. Call ToString( string ).
35 2. Remove leading whitespace Result(1).
36 3. If neither Result(2) nor any prefix of Result(2)
37 satisfies the syntax of a StrDecimalLiteral,
39 4. Compute the longest prefix of Result(2) which might
40 be Resusult(2) itself, that satisfies the syntax of
42 5. Return the number value for the MV of Result(4).
44 Note that parseFloate may interpret only a leading
45 portion of the string as a number value; it ignores any
46 characters that cannot be interpreted as part of the
47 notation of a decimal literal, and no indication is given
48 that such characters were ignored.
52 DecimalDigits.DecimalDigits opt ExponentPart opt
53 .DecimalDigits ExponentPart opt
54 DecimalDigits ExponentPart opt
56 Author: christine@netscape.com
60 var SECTION
= "15.1.2.3-2";
61 var VERSION
= "ECMA_1";
64 var BUGNUMBER
= "77391";
66 var testcases
= getTestCases();
68 writeHeaderToLog( SECTION
+ " parseFloat(string)");
71 function getTestCases() {
72 var array
= new Array();
75 array
[item
++] = new TestCase( SECTION
, "parseFloat(true)", Number
.NaN
, parseFloat(true) );
76 array
[item
++] = new TestCase( SECTION
, "parseFloat(false)", Number
.NaN
, parseFloat(false) );
77 array
[item
++] = new TestCase( SECTION
, "parseFloat('string')", Number
.NaN
, parseFloat("string") );
79 array
[item
++] = new TestCase( SECTION
, "parseFloat(' Infinity')", Number
.POSITIVE_INFINITY
, parseFloat("Infinity") );
80 // array[item++] = new TestCase( SECTION, "parseFloat(Infinity)", Number.POSITIVE_INFINITY, parseFloat(Infinity) );
82 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0')", 0, parseFloat(" 0") );
83 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -0')", -0, parseFloat(" -0") );
84 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +0')", 0, parseFloat(" +0") );
86 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1')", 1, parseFloat(" 1") );
87 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1')", -1, parseFloat(" -1") );
88 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1')", 1, parseFloat(" +1") );
90 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 2')", 2, parseFloat(" 2") );
91 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -2')", -2, parseFloat(" -2") );
92 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +2')", 2, parseFloat(" +2") );
94 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3')", 3, parseFloat(" 3") );
95 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3')", -3, parseFloat(" -3") );
96 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3')", 3, parseFloat(" +3") );
98 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 4')", 4, parseFloat(" 4") );
99 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -4')", -4, parseFloat(" -4") );
100 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +4')", 4, parseFloat(" +4") );
102 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 5')", 5, parseFloat(" 5") );
103 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -5')", -5, parseFloat(" -5") );
104 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +5')", 5, parseFloat(" +5") );
106 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 6')", 6, parseFloat(" 6") );
107 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -6')", -6, parseFloat(" -6") );
108 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +6')", 6, parseFloat(" +6") );
110 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 7')", 7, parseFloat(" 7") );
111 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -7')", -7, parseFloat(" -7") );
112 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +7')", 7, parseFloat(" +7") );
114 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 8')", 8, parseFloat(" 8") );
115 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -8')", -8, parseFloat(" -8") );
116 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +8')", 8, parseFloat(" +8") );
118 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 9')", 9, parseFloat(" 9") );
119 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -9')", -9, parseFloat(" -9") );
120 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +9')", 9, parseFloat(" +9") );
122 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3.14159')", 3.14159, parseFloat(" 3.14159") );
123 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3.14159')", -3.14159, parseFloat(" -3.14159") );
124 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3.14159')", 3.14159, parseFloat(" +3.14159") );
126 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3.')", 3, parseFloat(" 3.") );
127 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3.')", -3, parseFloat(" -3.") );
128 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3.')", 3, parseFloat(" +3.") );
130 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3.e1')", 30, parseFloat(" 3.e1") );
131 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3.e1')", -30, parseFloat(" -3.e1") );
132 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3.e1')", 30, parseFloat(" +3.e1") );
134 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3.e+1')", 30, parseFloat(" 3.e+1") );
135 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3.e+1')", -30, parseFloat(" -3.e+1") );
136 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3.e+1')", 30, parseFloat(" +3.e+1") );
138 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 3.e-1')", .30, parseFloat(" 3.e-1") );
139 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -3.e-1')", -.30, parseFloat(" -3.e-1") );
140 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +3.e-1')", .30, parseFloat(" +3.e-1") );
142 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt
144 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .00001')", 0.00001, parseFloat(" .00001") );
145 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.00001')", 0.00001, parseFloat(" +.00001") );
146 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -0.0001')", -0.00001, parseFloat(" -.00001") );
148 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01e2')", 1, parseFloat(" .01e2") );
149 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01e2')", 1, parseFloat(" +.01e2") );
150 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01e2')", -1, parseFloat(" -.01e2") );
152 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01e+2')", 1, parseFloat(" .01e+2") );
153 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01e+2')", 1, parseFloat(" +.01e+2") );
154 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01e+2')", -1, parseFloat(" -.01e+2") );
156 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01e-2')", 0.0001, parseFloat(" .01e-2") );
157 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01e-2')", 0.0001, parseFloat(" +.01e-2") );
158 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01e-2')", -0.0001, parseFloat(" -.01e-2") );
160 // StrDecimalLiteral::: DecimalDigits ExponentPart opt
162 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234e5')", 123400000, parseFloat(" 1234e5") );
163 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234e5')", 123400000, parseFloat(" +1234e5") );
164 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234e5')", -123400000, parseFloat(" -1234e5") );
166 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234e+5')", 123400000, parseFloat(" 1234e+5") );
167 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234e+5')", 123400000, parseFloat(" +1234e+5") );
168 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234e+5')", -123400000, parseFloat(" -1234e+5") );
170 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234e-5')", 0.01234, parseFloat(" 1234e-5") );
171 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234e-5')", 0.01234, parseFloat(" +1234e-5") );
172 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234e-5')", -0.01234, parseFloat(" -1234e-5") );
175 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01E2')", 1, parseFloat(" .01E2") );
176 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01E2')", 1, parseFloat(" +.01E2") );
177 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01E2')", -1, parseFloat(" -.01E2") );
179 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01E+2')", 1, parseFloat(" .01E+2") );
180 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01E+2')", 1, parseFloat(" +.01E+2") );
181 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01E+2')", -1, parseFloat(" -.01E+2") );
183 array
[item
++] = new TestCase( SECTION
, "parseFloat(' .01E-2')", 0.0001, parseFloat(" .01E-2") );
184 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +.01E-2')", 0.0001, parseFloat(" +.01E-2") );
185 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -.01E-2')", -0.0001, parseFloat(" -.01E-2") );
187 // StrDecimalLiteral::: DecimalDigits ExponentPart opt
188 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234E5')", 123400000, parseFloat(" 1234E5") );
189 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234E5')", 123400000, parseFloat(" +1234E5") );
190 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234E5')", -123400000, parseFloat(" -1234E5") );
192 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234E+5')", 123400000, parseFloat(" 1234E+5") );
193 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234E+5')", 123400000, parseFloat(" +1234E+5") );
194 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234E+5')", -123400000, parseFloat(" -1234E+5") );
196 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 1234E-5')", 0.01234, parseFloat(" 1234E-5") );
197 array
[item
++] = new TestCase( SECTION
, "parseFloat(' +1234E-5')", 0.01234, parseFloat(" +1234E-5") );
198 array
[item
++] = new TestCase( SECTION
, "parseFloat(' -1234E-5')", -0.01234, parseFloat(" -1234E-5") );
201 // hex cases should all return NaN
203 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x0')", 0, parseFloat(" 0x0"));
204 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x1')", 0, parseFloat(" 0x1"));
205 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x2')", 0, parseFloat(" 0x2"));
206 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x3')", 0, parseFloat(" 0x3"));
207 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x4')", 0, parseFloat(" 0x4"));
208 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x5')", 0, parseFloat(" 0x5"));
209 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x6')", 0, parseFloat(" 0x6"));
210 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x7')", 0, parseFloat(" 0x7"));
211 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x8')", 0, parseFloat(" 0x8"));
212 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0x9')", 0, parseFloat(" 0x9"));
213 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xa')", 0, parseFloat(" 0xa"));
214 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xb')", 0, parseFloat(" 0xb"));
215 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xc')", 0, parseFloat(" 0xc"));
216 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xd')", 0, parseFloat(" 0xd"));
217 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xe')", 0, parseFloat(" 0xe"));
218 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xf')", 0, parseFloat(" 0xf"));
219 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xA')", 0, parseFloat(" 0xA"));
220 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xB')", 0, parseFloat(" 0xB"));
221 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xC')", 0, parseFloat(" 0xC"));
222 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xD')", 0, parseFloat(" 0xD"));
223 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xE')", 0, parseFloat(" 0xE"));
224 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0xF')", 0, parseFloat(" 0xF"));
226 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X0')", 0, parseFloat(" 0X0"));
227 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X1')", 0, parseFloat(" 0X1"));
228 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X2')", 0, parseFloat(" 0X2"));
229 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X3')", 0, parseFloat(" 0X3"));
230 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X4')", 0, parseFloat(" 0X4"));
231 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X5')", 0, parseFloat(" 0X5"));
232 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X6')", 0, parseFloat(" 0X6"));
233 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X7')", 0, parseFloat(" 0X7"));
234 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X8')", 0, parseFloat(" 0X8"));
235 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0X9')", 0, parseFloat(" 0X9"));
236 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xa')", 0, parseFloat(" 0Xa"));
237 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xb')", 0, parseFloat(" 0Xb"));
238 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xc')", 0, parseFloat(" 0Xc"));
239 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xd')", 0, parseFloat(" 0Xd"));
240 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xe')", 0, parseFloat(" 0Xe"));
241 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0Xf')", 0, parseFloat(" 0Xf"));
242 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XA')", 0, parseFloat(" 0XA"));
243 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XB')", 0, parseFloat(" 0XB"));
244 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XC')", 0, parseFloat(" 0XC"));
245 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XD')", 0, parseFloat(" 0XD"));
246 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XE')", 0, parseFloat(" 0XE"));
247 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0XF')", 0, parseFloat(" 0XF"));
249 // A StringNumericLiteral may not use octal notation
251 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 00')", 0, parseFloat(" 00"));
252 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 01')", 1, parseFloat(" 01"));
253 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 02')", 2, parseFloat(" 02"));
254 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 03')", 3, parseFloat(" 03"));
255 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 04')", 4, parseFloat(" 04"));
256 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 05')", 5, parseFloat(" 05"));
257 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 06')", 6, parseFloat(" 06"));
258 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 07')", 7, parseFloat(" 07"));
259 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 010')", 10, parseFloat(" 010"));
260 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 011')", 11, parseFloat(" 011"));
262 // A StringNumericLIteral may have any number of leading 0 digits
264 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 001')", 1, parseFloat(" 001"));
265 array
[item
++] = new TestCase( SECTION
, "parseFloat(' 0001')", 1, parseFloat(" 0001"));
267 // A StringNumericLIteral may have any number of leading 0 digits
269 array
[item
++] = new TestCase( SECTION
, "parseFloat(001)", 1, parseFloat(001));
270 array
[item
++] = new TestCase( SECTION
, "parseFloat(0001)", 1, parseFloat(0001));
272 // make sure it' s reflexive
273 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.PI+' ')", Math
.PI
, parseFloat( ' ' +Math
.PI
+' '));
274 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.LN2+' ')", Math
.LN2
, parseFloat( ' ' +Math
.LN2
+' '));
275 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.LN10+' ')", Math
.LN10
, parseFloat( ' ' +Math
.LN10
+' '));
276 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.LOG2E+' ')", Math
.LOG2E
, parseFloat( ' ' +Math
.LOG2E
+' '));
277 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.LOG10E+' ')", Math
.LOG10E
, parseFloat( ' ' +Math
.LOG10E
+' '));
278 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.SQRT2+' ')", Math
.SQRT2
, parseFloat( ' ' +Math
.SQRT2
+' '));
279 array
[item
++] = new TestCase( SECTION
, "parseFloat( ' ' +Math.SQRT1_2+' ')", Math
.SQRT1_2
, parseFloat( ' ' +Math
.SQRT1_2
+' '));
284 function test( array
) {
285 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
286 testcases
[tc
].passed
= writeTestCaseResult(
287 testcases
[tc
].expect
,
288 testcases
[tc
].actual
,
289 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
291 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
294 return ( testcases
);