js/src/tests/ecma/GlobalObject/15.1.2.3-2.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 File Name: 15.1.2.3-2.js
michael@0 9 ECMA Section: 15.1.2.3 Function properties of the global object:
michael@0 10 parseFloat( string )
michael@0 11
michael@0 12 Description: The parseFloat function produces a number value dictated
michael@0 13 by the interpretation of the contents of the string
michael@0 14 argument defined as a decimal literal.
michael@0 15
michael@0 16 When the parseFloat function is called, the following
michael@0 17 steps are taken:
michael@0 18
michael@0 19 1. Call ToString( string ).
michael@0 20 2. Remove leading whitespace Result(1).
michael@0 21 3. If neither Result(2) nor any prefix of Result(2)
michael@0 22 satisfies the syntax of a StrDecimalLiteral,
michael@0 23 return NaN.
michael@0 24 4. Compute the longest prefix of Result(2) which might
michael@0 25 be Resusult(2) itself, that satisfies the syntax of
michael@0 26 a StrDecimalLiteral
michael@0 27 5. Return the number value for the MV of Result(4).
michael@0 28
michael@0 29 Note that parseFloate may interpret only a leading
michael@0 30 portion of the string as a number value; it ignores any
michael@0 31 characters that cannot be interpreted as part of the
michael@0 32 notation of a decimal literal, and no indication is given
michael@0 33 that such characters were ignored.
michael@0 34
michael@0 35 StrDecimalLiteral::
michael@0 36 Infinity
michael@0 37 DecimalDigits.DecimalDigits opt ExponentPart opt
michael@0 38 .DecimalDigits ExponentPart opt
michael@0 39 DecimalDigits ExponentPart opt
michael@0 40
michael@0 41 Author: christine@netscape.com
michael@0 42 Date: 28 october 1997
michael@0 43
michael@0 44 */
michael@0 45 var SECTION = "15.1.2.3-2";
michael@0 46 var VERSION = "ECMA_1";
michael@0 47 startTest();
michael@0 48
michael@0 49 var BUGNUMBER="none";
michael@0 50
michael@0 51 new TestCase( SECTION, "parseFloat(true)", Number.NaN, parseFloat(true) );
michael@0 52 new TestCase( SECTION, "parseFloat(false)", Number.NaN, parseFloat(false) );
michael@0 53 new TestCase( SECTION, "parseFloat('string')", Number.NaN, parseFloat("string") );
michael@0 54
michael@0 55 new TestCase( SECTION, "parseFloat(' Infinity')", Number.POSITIVE_INFINITY, parseFloat("Infinity") );
michael@0 56 // new TestCase( SECTION, "parseFloat(Infinity)", Number.POSITIVE_INFINITY, parseFloat(Infinity) );
michael@0 57
michael@0 58 new TestCase( SECTION, "parseFloat(' 0')", 0, parseFloat(" 0") );
michael@0 59 new TestCase( SECTION, "parseFloat(' -0')", -0, parseFloat(" -0") );
michael@0 60 new TestCase( SECTION, "parseFloat(' +0')", 0, parseFloat(" +0") );
michael@0 61
michael@0 62 new TestCase( SECTION, "parseFloat(' 1')", 1, parseFloat(" 1") );
michael@0 63 new TestCase( SECTION, "parseFloat(' -1')", -1, parseFloat(" -1") );
michael@0 64 new TestCase( SECTION, "parseFloat(' +1')", 1, parseFloat(" +1") );
michael@0 65
michael@0 66 new TestCase( SECTION, "parseFloat(' 2')", 2, parseFloat(" 2") );
michael@0 67 new TestCase( SECTION, "parseFloat(' -2')", -2, parseFloat(" -2") );
michael@0 68 new TestCase( SECTION, "parseFloat(' +2')", 2, parseFloat(" +2") );
michael@0 69
michael@0 70 new TestCase( SECTION, "parseFloat(' 3')", 3, parseFloat(" 3") );
michael@0 71 new TestCase( SECTION, "parseFloat(' -3')", -3, parseFloat(" -3") );
michael@0 72 new TestCase( SECTION, "parseFloat(' +3')", 3, parseFloat(" +3") );
michael@0 73
michael@0 74 new TestCase( SECTION, "parseFloat(' 4')", 4, parseFloat(" 4") );
michael@0 75 new TestCase( SECTION, "parseFloat(' -4')", -4, parseFloat(" -4") );
michael@0 76 new TestCase( SECTION, "parseFloat(' +4')", 4, parseFloat(" +4") );
michael@0 77
michael@0 78 new TestCase( SECTION, "parseFloat(' 5')", 5, parseFloat(" 5") );
michael@0 79 new TestCase( SECTION, "parseFloat(' -5')", -5, parseFloat(" -5") );
michael@0 80 new TestCase( SECTION, "parseFloat(' +5')", 5, parseFloat(" +5") );
michael@0 81
michael@0 82 new TestCase( SECTION, "parseFloat(' 6')", 6, parseFloat(" 6") );
michael@0 83 new TestCase( SECTION, "parseFloat(' -6')", -6, parseFloat(" -6") );
michael@0 84 new TestCase( SECTION, "parseFloat(' +6')", 6, parseFloat(" +6") );
michael@0 85
michael@0 86 new TestCase( SECTION, "parseFloat(' 7')", 7, parseFloat(" 7") );
michael@0 87 new TestCase( SECTION, "parseFloat(' -7')", -7, parseFloat(" -7") );
michael@0 88 new TestCase( SECTION, "parseFloat(' +7')", 7, parseFloat(" +7") );
michael@0 89
michael@0 90 new TestCase( SECTION, "parseFloat(' 8')", 8, parseFloat(" 8") );
michael@0 91 new TestCase( SECTION, "parseFloat(' -8')", -8, parseFloat(" -8") );
michael@0 92 new TestCase( SECTION, "parseFloat(' +8')", 8, parseFloat(" +8") );
michael@0 93
michael@0 94 new TestCase( SECTION, "parseFloat(' 9')", 9, parseFloat(" 9") );
michael@0 95 new TestCase( SECTION, "parseFloat(' -9')", -9, parseFloat(" -9") );
michael@0 96 new TestCase( SECTION, "parseFloat(' +9')", 9, parseFloat(" +9") );
michael@0 97
michael@0 98 new TestCase( SECTION, "parseFloat(' 3.14159')", 3.14159, parseFloat(" 3.14159") );
michael@0 99 new TestCase( SECTION, "parseFloat(' -3.14159')", -3.14159, parseFloat(" -3.14159") );
michael@0 100 new TestCase( SECTION, "parseFloat(' +3.14159')", 3.14159, parseFloat(" +3.14159") );
michael@0 101
michael@0 102 new TestCase( SECTION, "parseFloat(' 3.')", 3, parseFloat(" 3.") );
michael@0 103 new TestCase( SECTION, "parseFloat(' -3.')", -3, parseFloat(" -3.") );
michael@0 104 new TestCase( SECTION, "parseFloat(' +3.')", 3, parseFloat(" +3.") );
michael@0 105
michael@0 106 new TestCase( SECTION, "parseFloat(' 3.e1')", 30, parseFloat(" 3.e1") );
michael@0 107 new TestCase( SECTION, "parseFloat(' -3.e1')", -30, parseFloat(" -3.e1") );
michael@0 108 new TestCase( SECTION, "parseFloat(' +3.e1')", 30, parseFloat(" +3.e1") );
michael@0 109
michael@0 110 new TestCase( SECTION, "parseFloat(' 3.e+1')", 30, parseFloat(" 3.e+1") );
michael@0 111 new TestCase( SECTION, "parseFloat(' -3.e+1')", -30, parseFloat(" -3.e+1") );
michael@0 112 new TestCase( SECTION, "parseFloat(' +3.e+1')", 30, parseFloat(" +3.e+1") );
michael@0 113
michael@0 114 new TestCase( SECTION, "parseFloat(' 3.e-1')", .30, parseFloat(" 3.e-1") );
michael@0 115 new TestCase( SECTION, "parseFloat(' -3.e-1')", -.30, parseFloat(" -3.e-1") );
michael@0 116 new TestCase( SECTION, "parseFloat(' +3.e-1')", .30, parseFloat(" +3.e-1") );
michael@0 117
michael@0 118 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt
michael@0 119
michael@0 120 new TestCase( SECTION, "parseFloat(' .00001')", 0.00001, parseFloat(" .00001") );
michael@0 121 new TestCase( SECTION, "parseFloat(' +.00001')", 0.00001, parseFloat(" +.00001") );
michael@0 122 new TestCase( SECTION, "parseFloat(' -0.0001')", -0.00001, parseFloat(" -.00001") );
michael@0 123
michael@0 124 new TestCase( SECTION, "parseFloat(' .01e2')", 1, parseFloat(" .01e2") );
michael@0 125 new TestCase( SECTION, "parseFloat(' +.01e2')", 1, parseFloat(" +.01e2") );
michael@0 126 new TestCase( SECTION, "parseFloat(' -.01e2')", -1, parseFloat(" -.01e2") );
michael@0 127
michael@0 128 new TestCase( SECTION, "parseFloat(' .01e+2')", 1, parseFloat(" .01e+2") );
michael@0 129 new TestCase( SECTION, "parseFloat(' +.01e+2')", 1, parseFloat(" +.01e+2") );
michael@0 130 new TestCase( SECTION, "parseFloat(' -.01e+2')", -1, parseFloat(" -.01e+2") );
michael@0 131
michael@0 132 new TestCase( SECTION, "parseFloat(' .01e-2')", 0.0001, parseFloat(" .01e-2") );
michael@0 133 new TestCase( SECTION, "parseFloat(' +.01e-2')", 0.0001, parseFloat(" +.01e-2") );
michael@0 134 new TestCase( SECTION, "parseFloat(' -.01e-2')", -0.0001, parseFloat(" -.01e-2") );
michael@0 135
michael@0 136 // StrDecimalLiteral::: DecimalDigits ExponentPart opt
michael@0 137
michael@0 138 new TestCase( SECTION, "parseFloat(' 1234e5')", 123400000, parseFloat(" 1234e5") );
michael@0 139 new TestCase( SECTION, "parseFloat(' +1234e5')", 123400000, parseFloat(" +1234e5") );
michael@0 140 new TestCase( SECTION, "parseFloat(' -1234e5')", -123400000, parseFloat(" -1234e5") );
michael@0 141
michael@0 142 new TestCase( SECTION, "parseFloat(' 1234e+5')", 123400000, parseFloat(" 1234e+5") );
michael@0 143 new TestCase( SECTION, "parseFloat(' +1234e+5')", 123400000, parseFloat(" +1234e+5") );
michael@0 144 new TestCase( SECTION, "parseFloat(' -1234e+5')", -123400000, parseFloat(" -1234e+5") );
michael@0 145
michael@0 146 new TestCase( SECTION, "parseFloat(' 1234e-5')", 0.01234, parseFloat(" 1234e-5") );
michael@0 147 new TestCase( SECTION, "parseFloat(' +1234e-5')", 0.01234, parseFloat(" +1234e-5") );
michael@0 148 new TestCase( SECTION, "parseFloat(' -1234e-5')", -0.01234, parseFloat(" -1234e-5") );
michael@0 149
michael@0 150
michael@0 151 new TestCase( SECTION, "parseFloat(' .01E2')", 1, parseFloat(" .01E2") );
michael@0 152 new TestCase( SECTION, "parseFloat(' +.01E2')", 1, parseFloat(" +.01E2") );
michael@0 153 new TestCase( SECTION, "parseFloat(' -.01E2')", -1, parseFloat(" -.01E2") );
michael@0 154
michael@0 155 new TestCase( SECTION, "parseFloat(' .01E+2')", 1, parseFloat(" .01E+2") );
michael@0 156 new TestCase( SECTION, "parseFloat(' +.01E+2')", 1, parseFloat(" +.01E+2") );
michael@0 157 new TestCase( SECTION, "parseFloat(' -.01E+2')", -1, parseFloat(" -.01E+2") );
michael@0 158
michael@0 159 new TestCase( SECTION, "parseFloat(' .01E-2')", 0.0001, parseFloat(" .01E-2") );
michael@0 160 new TestCase( SECTION, "parseFloat(' +.01E-2')", 0.0001, parseFloat(" +.01E-2") );
michael@0 161 new TestCase( SECTION, "parseFloat(' -.01E-2')", -0.0001, parseFloat(" -.01E-2") );
michael@0 162
michael@0 163 // StrDecimalLiteral::: DecimalDigits ExponentPart opt
michael@0 164 new TestCase( SECTION, "parseFloat(' 1234E5')", 123400000, parseFloat(" 1234E5") );
michael@0 165 new TestCase( SECTION, "parseFloat(' +1234E5')", 123400000, parseFloat(" +1234E5") );
michael@0 166 new TestCase( SECTION, "parseFloat(' -1234E5')", -123400000, parseFloat(" -1234E5") );
michael@0 167
michael@0 168 new TestCase( SECTION, "parseFloat(' 1234E+5')", 123400000, parseFloat(" 1234E+5") );
michael@0 169 new TestCase( SECTION, "parseFloat(' +1234E+5')", 123400000, parseFloat(" +1234E+5") );
michael@0 170 new TestCase( SECTION, "parseFloat(' -1234E+5')", -123400000, parseFloat(" -1234E+5") );
michael@0 171
michael@0 172 new TestCase( SECTION, "parseFloat(' 1234E-5')", 0.01234, parseFloat(" 1234E-5") );
michael@0 173 new TestCase( SECTION, "parseFloat(' +1234E-5')", 0.01234, parseFloat(" +1234E-5") );
michael@0 174 new TestCase( SECTION, "parseFloat(' -1234E-5')", -0.01234, parseFloat(" -1234E-5") );
michael@0 175
michael@0 176
michael@0 177 // hex cases should all return NaN
michael@0 178
michael@0 179 new TestCase( SECTION, "parseFloat(' 0x0')", 0, parseFloat(" 0x0"));
michael@0 180 new TestCase( SECTION, "parseFloat(' 0x1')", 0, parseFloat(" 0x1"));
michael@0 181 new TestCase( SECTION, "parseFloat(' 0x2')", 0, parseFloat(" 0x2"));
michael@0 182 new TestCase( SECTION, "parseFloat(' 0x3')", 0, parseFloat(" 0x3"));
michael@0 183 new TestCase( SECTION, "parseFloat(' 0x4')", 0, parseFloat(" 0x4"));
michael@0 184 new TestCase( SECTION, "parseFloat(' 0x5')", 0, parseFloat(" 0x5"));
michael@0 185 new TestCase( SECTION, "parseFloat(' 0x6')", 0, parseFloat(" 0x6"));
michael@0 186 new TestCase( SECTION, "parseFloat(' 0x7')", 0, parseFloat(" 0x7"));
michael@0 187 new TestCase( SECTION, "parseFloat(' 0x8')", 0, parseFloat(" 0x8"));
michael@0 188 new TestCase( SECTION, "parseFloat(' 0x9')", 0, parseFloat(" 0x9"));
michael@0 189 new TestCase( SECTION, "parseFloat(' 0xa')", 0, parseFloat(" 0xa"));
michael@0 190 new TestCase( SECTION, "parseFloat(' 0xb')", 0, parseFloat(" 0xb"));
michael@0 191 new TestCase( SECTION, "parseFloat(' 0xc')", 0, parseFloat(" 0xc"));
michael@0 192 new TestCase( SECTION, "parseFloat(' 0xd')", 0, parseFloat(" 0xd"));
michael@0 193 new TestCase( SECTION, "parseFloat(' 0xe')", 0, parseFloat(" 0xe"));
michael@0 194 new TestCase( SECTION, "parseFloat(' 0xf')", 0, parseFloat(" 0xf"));
michael@0 195 new TestCase( SECTION, "parseFloat(' 0xA')", 0, parseFloat(" 0xA"));
michael@0 196 new TestCase( SECTION, "parseFloat(' 0xB')", 0, parseFloat(" 0xB"));
michael@0 197 new TestCase( SECTION, "parseFloat(' 0xC')", 0, parseFloat(" 0xC"));
michael@0 198 new TestCase( SECTION, "parseFloat(' 0xD')", 0, parseFloat(" 0xD"));
michael@0 199 new TestCase( SECTION, "parseFloat(' 0xE')", 0, parseFloat(" 0xE"));
michael@0 200 new TestCase( SECTION, "parseFloat(' 0xF')", 0, parseFloat(" 0xF"));
michael@0 201
michael@0 202 new TestCase( SECTION, "parseFloat(' 0X0')", 0, parseFloat(" 0X0"));
michael@0 203 new TestCase( SECTION, "parseFloat(' 0X1')", 0, parseFloat(" 0X1"));
michael@0 204 new TestCase( SECTION, "parseFloat(' 0X2')", 0, parseFloat(" 0X2"));
michael@0 205 new TestCase( SECTION, "parseFloat(' 0X3')", 0, parseFloat(" 0X3"));
michael@0 206 new TestCase( SECTION, "parseFloat(' 0X4')", 0, parseFloat(" 0X4"));
michael@0 207 new TestCase( SECTION, "parseFloat(' 0X5')", 0, parseFloat(" 0X5"));
michael@0 208 new TestCase( SECTION, "parseFloat(' 0X6')", 0, parseFloat(" 0X6"));
michael@0 209 new TestCase( SECTION, "parseFloat(' 0X7')", 0, parseFloat(" 0X7"));
michael@0 210 new TestCase( SECTION, "parseFloat(' 0X8')", 0, parseFloat(" 0X8"));
michael@0 211 new TestCase( SECTION, "parseFloat(' 0X9')", 0, parseFloat(" 0X9"));
michael@0 212 new TestCase( SECTION, "parseFloat(' 0Xa')", 0, parseFloat(" 0Xa"));
michael@0 213 new TestCase( SECTION, "parseFloat(' 0Xb')", 0, parseFloat(" 0Xb"));
michael@0 214 new TestCase( SECTION, "parseFloat(' 0Xc')", 0, parseFloat(" 0Xc"));
michael@0 215 new TestCase( SECTION, "parseFloat(' 0Xd')", 0, parseFloat(" 0Xd"));
michael@0 216 new TestCase( SECTION, "parseFloat(' 0Xe')", 0, parseFloat(" 0Xe"));
michael@0 217 new TestCase( SECTION, "parseFloat(' 0Xf')", 0, parseFloat(" 0Xf"));
michael@0 218 new TestCase( SECTION, "parseFloat(' 0XA')", 0, parseFloat(" 0XA"));
michael@0 219 new TestCase( SECTION, "parseFloat(' 0XB')", 0, parseFloat(" 0XB"));
michael@0 220 new TestCase( SECTION, "parseFloat(' 0XC')", 0, parseFloat(" 0XC"));
michael@0 221 new TestCase( SECTION, "parseFloat(' 0XD')", 0, parseFloat(" 0XD"));
michael@0 222 new TestCase( SECTION, "parseFloat(' 0XE')", 0, parseFloat(" 0XE"));
michael@0 223 new TestCase( SECTION, "parseFloat(' 0XF')", 0, parseFloat(" 0XF"));
michael@0 224
michael@0 225 // A StringNumericLiteral may not use octal notation
michael@0 226
michael@0 227 new TestCase( SECTION, "parseFloat(' 00')", 0, parseFloat(" 00"));
michael@0 228 new TestCase( SECTION, "parseFloat(' 01')", 1, parseFloat(" 01"));
michael@0 229 new TestCase( SECTION, "parseFloat(' 02')", 2, parseFloat(" 02"));
michael@0 230 new TestCase( SECTION, "parseFloat(' 03')", 3, parseFloat(" 03"));
michael@0 231 new TestCase( SECTION, "parseFloat(' 04')", 4, parseFloat(" 04"));
michael@0 232 new TestCase( SECTION, "parseFloat(' 05')", 5, parseFloat(" 05"));
michael@0 233 new TestCase( SECTION, "parseFloat(' 06')", 6, parseFloat(" 06"));
michael@0 234 new TestCase( SECTION, "parseFloat(' 07')", 7, parseFloat(" 07"));
michael@0 235 new TestCase( SECTION, "parseFloat(' 010')", 10, parseFloat(" 010"));
michael@0 236 new TestCase( SECTION, "parseFloat(' 011')", 11, parseFloat(" 011"));
michael@0 237
michael@0 238 // A StringNumericLIteral may have any number of leading 0 digits
michael@0 239
michael@0 240 new TestCase( SECTION, "parseFloat(' 001')", 1, parseFloat(" 001"));
michael@0 241 new TestCase( SECTION, "parseFloat(' 0001')", 1, parseFloat(" 0001"));
michael@0 242
michael@0 243 // A StringNumericLIteral may have any number of leading 0 digits
michael@0 244
michael@0 245 new TestCase( SECTION, "parseFloat(001)", 1, parseFloat(001));
michael@0 246 new TestCase( SECTION, "parseFloat(0001)", 1, parseFloat(0001));
michael@0 247
michael@0 248 // make sure it' s reflexive
michael@0 249 new TestCase( SECTION, "parseFloat( ' ' +Math.PI+' ')", Math.PI, parseFloat( ' ' +Math.PI+' '));
michael@0 250 new TestCase( SECTION, "parseFloat( ' ' +Math.LN2+' ')", Math.LN2, parseFloat( ' ' +Math.LN2+' '));
michael@0 251 new TestCase( SECTION, "parseFloat( ' ' +Math.LN10+' ')", Math.LN10, parseFloat( ' ' +Math.LN10+' '));
michael@0 252 new TestCase( SECTION, "parseFloat( ' ' +Math.LOG2E+' ')", Math.LOG2E, parseFloat( ' ' +Math.LOG2E+' '));
michael@0 253 new TestCase( SECTION, "parseFloat( ' ' +Math.LOG10E+' ')", Math.LOG10E, parseFloat( ' ' +Math.LOG10E+' '));
michael@0 254 new TestCase( SECTION, "parseFloat( ' ' +Math.SQRT2+' ')", Math.SQRT2, parseFloat( ' ' +Math.SQRT2+' '));
michael@0 255 new TestCase( SECTION, "parseFloat( ' ' +Math.SQRT1_2+' ')", Math.SQRT1_2, parseFloat( ' ' +Math.SQRT1_2+' '));
michael@0 256
michael@0 257 test();

mercurial