How to use testCase method in Jest

Best JavaScript code snippet using jest

15.1.2.3-1.js

Source:15.1.2.3-1.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 15.1.2.3.js24 ECMA Section: 15.1.2.3 Function properties of the global object:25 parseFloat( string )26 Description: The parseFloat function produces a number value dictated27 by the interpretation of the contents of the string28 argument defined as a decimal literal.29 When the parseFloat function is called, the following30 steps are taken:31 1. Call ToString( string ).32 2. Remove leading whitespace Result(1).33 3. If neither Result(2) nor any prefix of Result(2)34 satisfies the syntax of a StrDecimalLiteral,35 return NaN.36 4. Compute the longest prefix of Result(2) which might37 be Resusult(2) itself, that satisfies the syntax of38 a StrDecimalLiteral39 5. Return the number value for the MV of Result(4).40 Note that parseFloate may interpret only a leading41 portion of the string as a number value; it ignores any42 characters that cannot be interpreted as part of the43 notation of a decimal literal, and no indication is given44 that such characters were ignored.45 StrDecimalLiteral::46 Infinity47 DecimalDigits.DecimalDigits opt ExponentPart opt48 .DecimalDigits ExponentPart opt49 DecimalDigits ExponentPart opt50 Author: christine@netscape.com51 Date: 28 october 199752*/53 var SECTION = "15.1.2.3-1";54 var VERSION = "ECMA_1";55 startTest();56 var TITLE = "parseFloat(string)";57 var BUGNUMBER= "77391";58 writeHeaderToLog( SECTION + " "+ TITLE);59 var testcases = getTestCases();60 test();61function getTestCases() {62 var array = new Array();63 var item = 0;64 array[item++] = new TestCase( SECTION, "parseFloat.length", 1, parseFloat.length );65 array[item++] = new TestCase( SECTION, "parseFloat.length = null; parseFloat.length", 1, eval("parseFloat.length = null; parseFloat.length") );66 array[item++] = new TestCase( SECTION, "delete parseFloat.length", false, delete parseFloat.length );67 array[item++] = new TestCase( SECTION, "delete parseFloat.length; parseFloat.length", 1, eval("delete parseFloat.length; parseFloat.length") );68 array[item++] = new TestCase( SECTION, "var MYPROPS=''; for ( var p in parseFloat ) { MYPROPS += p }; MYPROPS", "", eval("var MYPROPS=''; for ( var p in parseFloat ) { MYPROPS += p }; MYPROPS") );69 array[item++] = new TestCase( SECTION, "parseFloat()", Number.NaN, parseFloat() );70 array[item++] = new TestCase( SECTION, "parseFloat('')", Number.NaN, parseFloat('') );71 array[item++] = new TestCase( SECTION, "parseFloat(' ')", Number.NaN, parseFloat(' ') );72 array[item++] = new TestCase( SECTION, "parseFloat(true)", Number.NaN, parseFloat(true) );73 array[item++] = new TestCase( SECTION, "parseFloat(false)", Number.NaN, parseFloat(false) );74 array[item++] = new TestCase( SECTION, "parseFloat('string')", Number.NaN, parseFloat("string") );75 array[item++] = new TestCase( SECTION, "parseFloat(' Infinity')", Infinity, parseFloat("Infinity") );76 array[item++] = new TestCase( SECTION, "parseFloat(' Infinity ')", Infinity, parseFloat(' Infinity ') );77 array[item++] = new TestCase( SECTION, "parseFloat('Infinity')", Infinity, parseFloat("Infinity") );78 array[item++] = new TestCase( SECTION, "parseFloat(Infinity)", Infinity, parseFloat(Infinity) );79 array[item++] = new TestCase( SECTION, "parseFloat(' +Infinity')", +Infinity, parseFloat("+Infinity") );80 array[item++] = new TestCase( SECTION, "parseFloat(' -Infinity ')", -Infinity, parseFloat(' -Infinity ') );81 array[item++] = new TestCase( SECTION, "parseFloat('+Infinity')", +Infinity, parseFloat("+Infinity") );82 array[item++] = new TestCase( SECTION, "parseFloat(-Infinity)", -Infinity, parseFloat(-Infinity) );83 array[item++] = new TestCase( SECTION, "parseFloat('0')", 0, parseFloat("0") );84 array[item++] = new TestCase( SECTION, "parseFloat('-0')", -0, parseFloat("-0") );85 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") );89 array[item++] = new TestCase( SECTION, "parseFloat('2')", 2, parseFloat("2") );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('3')", 3, parseFloat("3") );93 array[item++] = new TestCase( SECTION, "parseFloat('-3')", -3, parseFloat("-3") );94 array[item++] = new TestCase( SECTION, "parseFloat('+3')", 3, parseFloat("+3") );95 array[item++] = new TestCase( SECTION, "parseFloat('4')", 4, parseFloat("4") );96 array[item++] = new TestCase( SECTION, "parseFloat('-4')", -4, parseFloat("-4") );97 array[item++] = new TestCase( SECTION, "parseFloat('+4')", 4, parseFloat("+4") );98 array[item++] = new TestCase( SECTION, "parseFloat('5')", 5, parseFloat("5") );99 array[item++] = new TestCase( SECTION, "parseFloat('-5')", -5, parseFloat("-5") );100 array[item++] = new TestCase( SECTION, "parseFloat('+5')", 5, parseFloat("+5") );101 array[item++] = new TestCase( SECTION, "parseFloat('6')", 6, parseFloat("6") );102 array[item++] = new TestCase( SECTION, "parseFloat('-6')", -6, parseFloat("-6") );103 array[item++] = new TestCase( SECTION, "parseFloat('+6')", 6, parseFloat("+6") );104 array[item++] = new TestCase( SECTION, "parseFloat('7')", 7, parseFloat("7") );105 array[item++] = new TestCase( SECTION, "parseFloat('-7')", -7, parseFloat("-7") );106 array[item++] = new TestCase( SECTION, "parseFloat('+7')", 7, parseFloat("+7") );107 array[item++] = new TestCase( SECTION, "parseFloat('8')", 8, parseFloat("8") );108 array[item++] = new TestCase( SECTION, "parseFloat('-8')", -8, parseFloat("-8") );109 array[item++] = new TestCase( SECTION, "parseFloat('+8')", 8, parseFloat("+8") );110 array[item++] = new TestCase( SECTION, "parseFloat('9')", 9, parseFloat("9") );111 array[item++] = new TestCase( SECTION, "parseFloat('-9')", -9, parseFloat("-9") );112 array[item++] = new TestCase( SECTION, "parseFloat('+9')", 9, parseFloat("+9") );113 array[item++] = new TestCase( SECTION, "parseFloat('3.14159')", 3.14159, parseFloat("3.14159") );114 array[item++] = new TestCase( SECTION, "parseFloat('-3.14159')", -3.14159, parseFloat("-3.14159") );115 array[item++] = new TestCase( SECTION, "parseFloat('+3.14159')", 3.14159, parseFloat("+3.14159") );116 array[item++] = new TestCase( SECTION, "parseFloat('3.')", 3, parseFloat("3.") );117 array[item++] = new TestCase( SECTION, "parseFloat('-3.')", -3, parseFloat("-3.") );118 array[item++] = new TestCase( SECTION, "parseFloat('+3.')", 3, parseFloat("+3.") );119 array[item++] = new TestCase( SECTION, "parseFloat('3.e1')", 30, parseFloat("3.e1") );120 array[item++] = new TestCase( SECTION, "parseFloat('-3.e1')", -30, parseFloat("-3.e1") );121 array[item++] = new TestCase( SECTION, "parseFloat('+3.e1')", 30, parseFloat("+3.e1") );122 array[item++] = new TestCase( SECTION, "parseFloat('3.e+1')", 30, parseFloat("3.e+1") );123 array[item++] = new TestCase( SECTION, "parseFloat('-3.e+1')", -30, parseFloat("-3.e+1") );124 array[item++] = new TestCase( SECTION, "parseFloat('+3.e+1')", 30, parseFloat("+3.e+1") );125 array[item++] = new TestCase( SECTION, "parseFloat('3.e-1')", .30, parseFloat("3.e-1") );126 array[item++] = new TestCase( SECTION, "parseFloat('-3.e-1')", -.30, parseFloat("-3.e-1") );127 array[item++] = new TestCase( SECTION, "parseFloat('+3.e-1')", .30, parseFloat("+3.e-1") );128 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt129 array[item++] = new TestCase( SECTION, "parseFloat('.00001')", 0.00001, parseFloat(".00001") );130 array[item++] = new TestCase( SECTION, "parseFloat('+.00001')", 0.00001, parseFloat("+.00001") );131 array[item++] = new TestCase( SECTION, "parseFloat('-0.0001')", -0.00001, parseFloat("-.00001") );132 array[item++] = new TestCase( SECTION, "parseFloat('.01e2')", 1, parseFloat(".01e2") );133 array[item++] = new TestCase( SECTION, "parseFloat('+.01e2')", 1, parseFloat("+.01e2") );134 array[item++] = new TestCase( SECTION, "parseFloat('-.01e2')", -1, parseFloat("-.01e2") );135 array[item++] = new TestCase( SECTION, "parseFloat('.01e+2')", 1, parseFloat(".01e+2") );136 array[item++] = new TestCase( SECTION, "parseFloat('+.01e+2')", 1, parseFloat("+.01e+2") );137 array[item++] = new TestCase( SECTION, "parseFloat('-.01e+2')", -1, parseFloat("-.01e+2") );138 array[item++] = new TestCase( SECTION, "parseFloat('.01e-2')", 0.0001, parseFloat(".01e-2") );139 array[item++] = new TestCase( SECTION, "parseFloat('+.01e-2')", 0.0001, parseFloat("+.01e-2") );140 array[item++] = new TestCase( SECTION, "parseFloat('-.01e-2')", -0.0001, parseFloat("-.01e-2") );141 // StrDecimalLiteral::: DecimalDigits ExponentPart opt142 array[item++] = new TestCase( SECTION, "parseFloat('1234e5')", 123400000, parseFloat("1234e5") );143 array[item++] = new TestCase( SECTION, "parseFloat('+1234e5')", 123400000, parseFloat("+1234e5") );144 array[item++] = new TestCase( SECTION, "parseFloat('-1234e5')", -123400000, parseFloat("-1234e5") );145 array[item++] = new TestCase( SECTION, "parseFloat('1234e+5')", 123400000, parseFloat("1234e+5") );146 array[item++] = new TestCase( SECTION, "parseFloat('+1234e+5')", 123400000, parseFloat("+1234e+5") );147 array[item++] = new TestCase( SECTION, "parseFloat('-1234e+5')", -123400000, parseFloat("-1234e+5") );148 array[item++] = new TestCase( SECTION, "parseFloat('1234e-5')", 0.01234, parseFloat("1234e-5") );149 array[item++] = new TestCase( SECTION, "parseFloat('+1234e-5')", 0.01234, parseFloat("+1234e-5") );150 array[item++] = new TestCase( SECTION, "parseFloat('-1234e-5')", -0.01234, parseFloat("-1234e-5") );151 array[item++] = new TestCase( SECTION, "parseFloat(0)", 0, parseFloat(0) );152 array[item++] = new TestCase( SECTION, "parseFloat(-0)", -0, parseFloat(-0) );153 array[item++] = new TestCase( SECTION, "parseFloat(1)", 1, parseFloat(1) );154 array[item++] = new TestCase( SECTION, "parseFloat(-1)", -1, parseFloat(-1) );155 array[item++] = new TestCase( SECTION, "parseFloat(2)", 2, parseFloat(2) );156 array[item++] = new TestCase( SECTION, "parseFloat(-2)", -2, parseFloat(-2) );157 array[item++] = new TestCase( SECTION, "parseFloat(3)", 3, parseFloat(3) );158 array[item++] = new TestCase( SECTION, "parseFloat(-3)", -3, parseFloat(-3) );159 array[item++] = new TestCase( SECTION, "parseFloat(4)", 4, parseFloat(4) );160 array[item++] = new TestCase( SECTION, "parseFloat(-4)", -4, parseFloat(-4) );161 array[item++] = new TestCase( SECTION, "parseFloat(5)", 5, parseFloat(5) );162 array[item++] = new TestCase( SECTION, "parseFloat(-5)", -5, parseFloat(-5) );163 array[item++] = new TestCase( SECTION, "parseFloat(6)", 6, parseFloat(6) );164 array[item++] = new TestCase( SECTION, "parseFloat(-6)", -6, parseFloat(-6) );165 array[item++] = new TestCase( SECTION, "parseFloat(7)", 7, parseFloat(7) );166 array[item++] = new TestCase( SECTION, "parseFloat(-7)", -7, parseFloat(-7) );167 array[item++] = new TestCase( SECTION, "parseFloat(8)", 8, parseFloat(8) );168 array[item++] = new TestCase( SECTION, "parseFloat(-8)", -8, parseFloat(-8) );169 array[item++] = new TestCase( SECTION, "parseFloat(9)", 9, parseFloat(9) );170 array[item++] = new TestCase( SECTION, "parseFloat(-9)", -9, parseFloat(-9) );171 array[item++] = new TestCase( SECTION, "parseFloat(3.14159)", 3.14159, parseFloat(3.14159) );172 array[item++] = new TestCase( SECTION, "parseFloat(-3.14159)", -3.14159, parseFloat(-3.14159) );173 array[item++] = new TestCase( SECTION, "parseFloat(3.)", 3, parseFloat(3.) );174 array[item++] = new TestCase( SECTION, "parseFloat(-3.)", -3, parseFloat(-3.) );175 array[item++] = new TestCase( SECTION, "parseFloat(3.e1)", 30, parseFloat(3.e1) );176 array[item++] = new TestCase( SECTION, "parseFloat(-3.e1)", -30, parseFloat(-3.e1) );177 array[item++] = new TestCase( SECTION, "parseFloat(3.e+1)", 30, parseFloat(3.e+1) );178 array[item++] = new TestCase( SECTION, "parseFloat(-3.e+1)", -30, parseFloat(-3.e+1) );179 array[item++] = new TestCase( SECTION, "parseFloat(3.e-1)", .30, parseFloat(3.e-1) );180 array[item++] = new TestCase( SECTION, "parseFloat(-3.e-1)", -.30, parseFloat(-3.e-1) );181 array[item++] = new TestCase( SECTION, "parseFloat(3.E1)", 30, parseFloat(3.E1) );182 array[item++] = new TestCase( SECTION, "parseFloat(-3.E1)", -30, parseFloat(-3.E1) );183 array[item++] = new TestCase( SECTION, "parseFloat(3.E+1)", 30, parseFloat(3.E+1) );184 array[item++] = new TestCase( SECTION, "parseFloat(-3.E+1)", -30, parseFloat(-3.E+1) );185 array[item++] = new TestCase( SECTION, "parseFloat(3.E-1)", .30, parseFloat(3.E-1) );186 array[item++] = new TestCase( SECTION, "parseFloat(-3.E-1)", -.30, parseFloat(-3.E-1) );187 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt188 array[item++] = new TestCase( SECTION, "parseFloat(.00001)", 0.00001, parseFloat(.00001) );189 array[item++] = new TestCase( SECTION, "parseFloat(-0.0001)", -0.00001, parseFloat(-.00001) );190 array[item++] = new TestCase( SECTION, "parseFloat(.01e2)", 1, parseFloat(.01e2) );191 array[item++] = new TestCase( SECTION, "parseFloat(-.01e2)", -1, parseFloat(-.01e2) );192 array[item++] = new TestCase( SECTION, "parseFloat(.01e+2)", 1, parseFloat(.01e+2) );193 array[item++] = new TestCase( SECTION, "parseFloat(-.01e+2)", -1, parseFloat(-.01e+2) );194 array[item++] = new TestCase( SECTION, "parseFloat(.01e-2)", 0.0001, parseFloat(.01e-2) );195 array[item++] = new TestCase( SECTION, "parseFloat(-.01e-2)", -0.0001, parseFloat(-.01e-2) );196 // StrDecimalLiteral::: DecimalDigits ExponentPart opt197 array[item++] = new TestCase( SECTION, "parseFloat(1234e5)", 123400000, parseFloat(1234e5) );198 array[item++] = new TestCase( SECTION, "parseFloat(-1234e5)", -123400000, parseFloat(-1234e5) );199 array[item++] = new TestCase( SECTION, "parseFloat(1234e+5)", 123400000, parseFloat(1234e+5) );200 array[item++] = new TestCase( SECTION, "parseFloat(-1234e+5)", -123400000, parseFloat(-1234e+5) );201 array[item++] = new TestCase( SECTION, "parseFloat(1234e-5)", 0.01234, parseFloat(1234e-5) );202 array[item++] = new TestCase( SECTION, "parseFloat(-1234e-5)", -0.01234, parseFloat(-1234e-5) );203 // hex cases should all return 0 (0 is the longest string that satisfies a StringDecimalLiteral)204 array[item++] = new TestCase( SECTION, "parseFloat('0x0')", 0, parseFloat("0x0"));205 array[item++] = new TestCase( SECTION, "parseFloat('0x1')", 0, parseFloat("0x1"));206 array[item++] = new TestCase( SECTION, "parseFloat('0x2')", 0, parseFloat("0x2"));207 array[item++] = new TestCase( SECTION, "parseFloat('0x3')", 0, parseFloat("0x3"));208 array[item++] = new TestCase( SECTION, "parseFloat('0x4')", 0, parseFloat("0x4"));209 array[item++] = new TestCase( SECTION, "parseFloat('0x5')", 0, parseFloat("0x5"));210 array[item++] = new TestCase( SECTION, "parseFloat('0x6')", 0, parseFloat("0x6"));211 array[item++] = new TestCase( SECTION, "parseFloat('0x7')", 0, parseFloat("0x7"));212 array[item++] = new TestCase( SECTION, "parseFloat('0x8')", 0, parseFloat("0x8"));213 array[item++] = new TestCase( SECTION, "parseFloat('0x9')", 0, parseFloat("0x9"));214 array[item++] = new TestCase( SECTION, "parseFloat('0xa')", 0, parseFloat("0xa"));215 array[item++] = new TestCase( SECTION, "parseFloat('0xb')", 0, parseFloat("0xb"));216 array[item++] = new TestCase( SECTION, "parseFloat('0xc')", 0, parseFloat("0xc"));217 array[item++] = new TestCase( SECTION, "parseFloat('0xd')", 0, parseFloat("0xd"));218 array[item++] = new TestCase( SECTION, "parseFloat('0xe')", 0, parseFloat("0xe"));219 array[item++] = new TestCase( SECTION, "parseFloat('0xf')", 0, parseFloat("0xf"));220 array[item++] = new TestCase( SECTION, "parseFloat('0xA')", 0, parseFloat("0xA"));221 array[item++] = new TestCase( SECTION, "parseFloat('0xB')", 0, parseFloat("0xB"));222 array[item++] = new TestCase( SECTION, "parseFloat('0xC')", 0, parseFloat("0xC"));223 array[item++] = new TestCase( SECTION, "parseFloat('0xD')", 0, parseFloat("0xD"));224 array[item++] = new TestCase( SECTION, "parseFloat('0xE')", 0, parseFloat("0xE"));225 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"));248 array[item++] = new TestCase( SECTION, "parseFloat(' 0XF ')", 0, parseFloat(" 0XF "));249 // hex literals should still succeed250 array[item++] = new TestCase( SECTION, "parseFloat(0x0)", 0, parseFloat(0x0));251 array[item++] = new TestCase( SECTION, "parseFloat(0x1)", 1, parseFloat(0x1));252 array[item++] = new TestCase( SECTION, "parseFloat(0x2)", 2, parseFloat(0x2));253 array[item++] = new TestCase( SECTION, "parseFloat(0x3)", 3, parseFloat(0x3));254 array[item++] = new TestCase( SECTION, "parseFloat(0x4)", 4, parseFloat(0x4));255 array[item++] = new TestCase( SECTION, "parseFloat(0x5)", 5, parseFloat(0x5));256 array[item++] = new TestCase( SECTION, "parseFloat(0x6)", 6, parseFloat(0x6));257 array[item++] = new TestCase( SECTION, "parseFloat(0x7)", 7, parseFloat(0x7));258 array[item++] = new TestCase( SECTION, "parseFloat(0x8)", 8, parseFloat(0x8));259 array[item++] = new TestCase( SECTION, "parseFloat(0x9)", 9, parseFloat(0x9));260 array[item++] = new TestCase( SECTION, "parseFloat(0xa)", 10, parseFloat(0xa));261 array[item++] = new TestCase( SECTION, "parseFloat(0xb)", 11, parseFloat(0xb));262 array[item++] = new TestCase( SECTION, "parseFloat(0xc)", 12, parseFloat(0xc));263 array[item++] = new TestCase( SECTION, "parseFloat(0xd)", 13, parseFloat(0xd));264 array[item++] = new TestCase( SECTION, "parseFloat(0xe)", 14, parseFloat(0xe));265 array[item++] = new TestCase( SECTION, "parseFloat(0xf)", 15, parseFloat(0xf));266 array[item++] = new TestCase( SECTION, "parseFloat(0xA)", 10, parseFloat(0xA));267 array[item++] = new TestCase( SECTION, "parseFloat(0xB)", 11, parseFloat(0xB));268 array[item++] = new TestCase( SECTION, "parseFloat(0xC)", 12, parseFloat(0xC));269 array[item++] = new TestCase( SECTION, "parseFloat(0xD)", 13, parseFloat(0xD));270 array[item++] = new TestCase( SECTION, "parseFloat(0xE)", 14, parseFloat(0xE));271 array[item++] = new TestCase( SECTION, "parseFloat(0xF)", 15, parseFloat(0xF));272 array[item++] = new TestCase( SECTION, "parseFloat(0X0)", 0, parseFloat(0X0));273 array[item++] = new TestCase( SECTION, "parseFloat(0X1)", 1, parseFloat(0X1));274 array[item++] = new TestCase( SECTION, "parseFloat(0X2)", 2, parseFloat(0X2));275 array[item++] = new TestCase( SECTION, "parseFloat(0X3)", 3, parseFloat(0X3));276 array[item++] = new TestCase( SECTION, "parseFloat(0X4)", 4, parseFloat(0X4));277 array[item++] = new TestCase( SECTION, "parseFloat(0X5)", 5, parseFloat(0X5));278 array[item++] = new TestCase( SECTION, "parseFloat(0X6)", 6, parseFloat(0X6));279 array[item++] = new TestCase( SECTION, "parseFloat(0X7)", 7, parseFloat(0X7));280 array[item++] = new TestCase( SECTION, "parseFloat(0X8)", 8, parseFloat(0X8));281 array[item++] = new TestCase( SECTION, "parseFloat(0X9)", 9, parseFloat(0X9));282 array[item++] = new TestCase( SECTION, "parseFloat(0Xa)", 10, parseFloat(0Xa));283 array[item++] = new TestCase( SECTION, "parseFloat(0Xb)", 11, parseFloat(0Xb));284 array[item++] = new TestCase( SECTION, "parseFloat(0Xc)", 12, parseFloat(0Xc));285 array[item++] = new TestCase( SECTION, "parseFloat(0Xd)", 13, parseFloat(0Xd));286 array[item++] = new TestCase( SECTION, "parseFloat(0Xe)", 14, parseFloat(0Xe));287 array[item++] = new TestCase( SECTION, "parseFloat(0Xf)", 15, parseFloat(0Xf));288 array[item++] = new TestCase( SECTION, "parseFloat(0XA)", 10, parseFloat(0XA));289 array[item++] = new TestCase( SECTION, "parseFloat(0XB)", 11, parseFloat(0XB));290 array[item++] = new TestCase( SECTION, "parseFloat(0XC)", 12, parseFloat(0XC));291 array[item++] = new TestCase( SECTION, "parseFloat(0XD)", 13, parseFloat(0XD));292 array[item++] = new TestCase( SECTION, "parseFloat(0XE)", 14, parseFloat(0XE));293 array[item++] = new TestCase( SECTION, "parseFloat(0XF)", 15, parseFloat(0XF));294 // A StringNumericLiteral may not use octal notation295 array[item++] = new TestCase( SECTION, "parseFloat('00')", 0, parseFloat("00"));296 array[item++] = new TestCase( SECTION, "parseFloat('01')", 1, parseFloat("01"));297 array[item++] = new TestCase( SECTION, "parseFloat('02')", 2, parseFloat("02"));298 array[item++] = new TestCase( SECTION, "parseFloat('03')", 3, parseFloat("03"));299 array[item++] = new TestCase( SECTION, "parseFloat('04')", 4, parseFloat("04"));300 array[item++] = new TestCase( SECTION, "parseFloat('05')", 5, parseFloat("05"));301 array[item++] = new TestCase( SECTION, "parseFloat('06')", 6, parseFloat("06"));302 array[item++] = new TestCase( SECTION, "parseFloat('07')", 7, parseFloat("07"));303 array[item++] = new TestCase( SECTION, "parseFloat('010')", 10, parseFloat("010"));304 array[item++] = new TestCase( SECTION, "parseFloat('011')", 11, parseFloat("011"));305 // A StringNumericLIteral may have any number of leading 0 digits306 array[item++] = new TestCase( SECTION, "parseFloat('001')", 1, parseFloat("001"));307 array[item++] = new TestCase( SECTION, "parseFloat('0001')", 1, parseFloat("0001"));308 array[item++] = new TestCase( SECTION, "parseFloat(' 0001 ')", 1, parseFloat(" 0001 "));309 // an octal numeric literal should be treated as an octal310 array[item++] = new TestCase( SECTION, "parseFloat(00)", 0, parseFloat(00));311 array[item++] = new TestCase( SECTION, "parseFloat(01)", 1, parseFloat(01));312 array[item++] = new TestCase( SECTION, "parseFloat(02)", 2, parseFloat(02));313 array[item++] = new TestCase( SECTION, "parseFloat(03)", 3, parseFloat(03));314 array[item++] = new TestCase( SECTION, "parseFloat(04)", 4, parseFloat(04));315 array[item++] = new TestCase( SECTION, "parseFloat(05)", 5, parseFloat(05));316 array[item++] = new TestCase( SECTION, "parseFloat(06)", 6, parseFloat(06));317 array[item++] = new TestCase( SECTION, "parseFloat(07)", 7, parseFloat(07));318 array[item++] = new TestCase( SECTION, "parseFloat(010)", 8, parseFloat(010));319 array[item++] = new TestCase( SECTION, "parseFloat(011)", 9, parseFloat(011));320 // A StringNumericLIteral may have any number of leading 0 digits321 array[item++] = new TestCase( SECTION, "parseFloat(001)", 1, parseFloat(001));322 array[item++] = new TestCase( SECTION, "parseFloat(0001)", 1, parseFloat(0001));323 // make sure it's reflexive324 array[item++] = new TestCase( SECTION, "parseFloat(Math.PI)", Math.PI, parseFloat(Math.PI));325 array[item++] = new TestCase( SECTION, "parseFloat(Math.LN2)", Math.LN2, parseFloat(Math.LN2));326 array[item++] = new TestCase( SECTION, "parseFloat(Math.LN10)", Math.LN10, parseFloat(Math.LN10));327 array[item++] = new TestCase( SECTION, "parseFloat(Math.LOG2E)", Math.LOG2E, parseFloat(Math.LOG2E));328 array[item++] = new TestCase( SECTION, "parseFloat(Math.LOG10E)", Math.LOG10E, parseFloat(Math.LOG10E));329 array[item++] = new TestCase( SECTION, "parseFloat(Math.SQRT2)", Math.SQRT2, parseFloat(Math.SQRT2));330 array[item++] = new TestCase( SECTION, "parseFloat(Math.SQRT1_2)", Math.SQRT1_2, parseFloat(Math.SQRT1_2));331 array[item++] = new TestCase( SECTION, "parseFloat(Math.PI+'')", Math.PI, parseFloat(Math.PI+''));332 array[item++] = new TestCase( SECTION, "parseFloat(Math.LN2+'')", Math.LN2, parseFloat(Math.LN2+''));333 array[item++] = new TestCase( SECTION, "parseFloat(Math.LN10+'')", Math.LN10, parseFloat(Math.LN10+''));334 array[item++] = new TestCase( SECTION, "parseFloat(Math.LOG2E+'')", Math.LOG2E, parseFloat(Math.LOG2E+''));335 array[item++] = new TestCase( SECTION, "parseFloat(Math.LOG10E+'')", Math.LOG10E, parseFloat(Math.LOG10E+''));336 array[item++] = new TestCase( SECTION, "parseFloat(Math.SQRT2+'')", Math.SQRT2, parseFloat(Math.SQRT2+''));337 array[item++] = new TestCase( SECTION, "parseFloat(Math.SQRT1_2+'')", Math.SQRT1_2, parseFloat(Math.SQRT1_2+''));338 return ( array );339}340function test() {341 for ( tc=0; tc < testcases.length; tc++ ) {342 testcases[tc].passed = writeTestCaseResult(343 testcases[tc].expect,344 testcases[tc].actual,345 testcases[tc].description +" = "+ testcases[tc].actual );346 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";347 }348 stopTest();349 return ( testcases );...

Full Screen

Full Screen

9.3.1-3.js

Source:9.3.1-3.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 9.3.1-3.js24 ECMA Section: 9.3 Type Conversion: ToNumber25 Description: rules for converting an argument to a number.26 see 9.3.1 for cases for converting strings to numbers.27 special cases:28 undefined NaN29 Null NaN30 Boolean 1 if true; +0 if false31 Number the argument ( no conversion )32 String see test 9.3.133 Object see test 9.3-134 Test cases provided by waldemar.35 Author: christine@netscape.com36 Date: 10 june 199837*/38var SECTION = "9.3.1-3";39var VERSION = "ECMA_1";40 startTest();41var BUGNUMBER="129087";42var TITLE = "Number To String, String To Number";43writeHeaderToLog( SECTION + " "+ TITLE);44var testcases = new Array();45// test case from http://scopus.mcom.com/bugsplat/show_bug.cgi?id=31295446var z = 0;47testcases[tc++] = new TestCase(48 SECTION,49 "var z = 0; print(1/-z)",50 -Infinity,51 1/-z );52// test cases from bug http://scopus.mcom.com/bugsplat/show_bug.cgi?id=12288253testcases[tc++] = new TestCase( SECTION,54 '- -"0x80000000"',55 2147483648,56 - -"0x80000000" );57testcases[tc++] = new TestCase( SECTION,58 '- -"0x100000000"',59 4294967296,60 - -"0x100000000" );61testcases[tc++] = new TestCase( SECTION,62 '- "-0x123456789abcde8"',63 81985529216486880,64 - "-0x123456789abcde8" );65// Convert some large numbers to string66testcases[tc++] = new TestCase( SECTION,67 "1e2000 +''",68 "Infinity",69 1e2000 +"" );70testcases[tc++] = new TestCase( SECTION,71 "1e2000",72 Infinity,73 1e2000 );74testcases[tc++] = new TestCase( SECTION,75 "-1e2000 +''",76 "-Infinity",77 -1e2000 +"" );78testcases[tc++] = new TestCase( SECTION,79 "-\"1e2000\"",80 -Infinity,81 -"1e2000" );82testcases[tc++] = new TestCase( SECTION,83 "-\"-1e2000\" +''",84 "Infinity",85 -"-1e2000" +"" );86testcases[tc++] = new TestCase( SECTION,87 "1e-2000",88 0,89 1e-2000 );90testcases[tc++] = new TestCase( SECTION,91 "1/1e-2000",92 Infinity,93 1/1e-2000 );94// convert some strings to large numbers95testcases[tc++] = new TestCase( SECTION,96 "1/-1e-2000",97 -Infinity,98 1/-1e-2000 );99testcases[tc++] = new TestCase( SECTION,100 "1/\"1e-2000\"",101 Infinity,102 1/"1e-2000" );103testcases[tc++] = new TestCase( SECTION,104 "1/\"-1e-2000\"",105 -Infinity,106 1/"-1e-2000" );107testcases[tc++] = new TestCase( SECTION,108 "parseFloat(\"1e2000\")",109 Infinity,110 parseFloat("1e2000") );111testcases[tc++] = new TestCase( SECTION,112 "parseFloat(\"1e-2000\")",113 0,114 parseFloat("1e-2000") );115testcases[tc++] = new TestCase( SECTION,116 "1.7976931348623157E+308",117 1.7976931348623157e+308,118 1.7976931348623157E+308 );119testcases[tc++] = new TestCase( SECTION,120 "1.7976931348623158e+308",121 1.7976931348623157e+308,122 1.7976931348623158e+308 );123testcases[tc++] = new TestCase( SECTION,124 "1.7976931348623159e+308",125 Infinity,126 1.7976931348623159e+308 );127s =128"17976931348623158079372897140530341507993413271003782693617377898044496829276475094664901797758720709633028641669288791094655554785194040263065748867150582068";129testcases[tc++] = new TestCase( SECTION,130 "s = " + s +"; s +="+131"\"190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779\""+132+"; s",133"17976931348623158079372897140530341507993413271003782693617377898044496829276475094664901797758720709633028641669288791094655554785194040263065748867150582068190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779",134s +=135"190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779"136);137s1 = s+1;138testcases[tc++] = new TestCase( SECTION,139"s1 = s+1; s1",140"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791",141s1 );142/***** This answer is preferred but -Infinity is also acceptable here *****/143testcases[tc++] = new TestCase( SECTION,144"-s1 == Infinity || s1 == 1.7976931348623157e+308",145true,146-s1 == Infinity || s1 == 1.7976931348623157e+308 );147s2 = s + 2;148testcases[tc++] = new TestCase( SECTION,149"s2 = s+2; s2",150"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792",151s2 );152// ***** This answer is preferred but -1.7976931348623157e+308 is also acceptable here *****153testcases[tc++] = new TestCase( SECTION,154"-s2 == -Infinity || -s2 == -1.7976931348623157e+308 ",155true,156-s2 == -Infinity || -s2 == -1.7976931348623157e+308 );157s3 = s+3;158testcases[tc++] = new TestCase( SECTION,159"s3 = s+3; s3",160"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497793",161s3 );162//***** This answer is preferred but -1.7976931348623157e+308 is also acceptable here *****163testcases[tc++] = new TestCase( SECTION,164"-s3 == -Infinity || -s3 == -1.7976931348623157e+308",165true,166-s3 == -Infinity || -s3 == -1.7976931348623157e+308 );167//***** This answer is preferred but Infinity is also acceptable here *****168testcases[tc++] = new TestCase( SECTION,169"parseInt(s1,10) == 1.7976931348623157e+308 || parseInt(s1,10) == Infinity",170true,171parseInt(s1,10) == 1.7976931348623157e+308 || parseInt(s1,10) == Infinity );172//***** This answer is preferred but 1.7976931348623157e+308 is also acceptable here *****173testcases[tc++] = new TestCase( SECTION,174"parseInt(s2,10) == Infinity || parseInt(s2,10) == 1.7976931348623157e+308",175true ,176parseInt(s2,10) == Infinity || parseInt(s2,10) == 1.7976931348623157e+308 );177//***** This answer is preferred but Infinity is also acceptable here *****178testcases[tc++] = new TestCase( SECTION,179"parseInt(s1) == 1.7976931348623157e+308 || parseInt(s1) == Infinity",180true,181parseInt(s1) == 1.7976931348623157e+308 || parseInt(s1) == Infinity);182//***** This answer is preferred but 1.7976931348623157e+308 is also acceptable here *****183testcases[tc++] = new TestCase( SECTION,184"parseInt(s2) == Infinity || parseInt(s2) == 1.7976931348623157e+308",185true,186parseInt(s2) == Infinity || parseInt(s2) == 1.7976931348623157e+308 );187testcases[tc++] = new TestCase( SECTION,188 "0x12345678",189 305419896,190 0x12345678 );191testcases[tc++] = new TestCase( SECTION,192 "0x80000000",193 2147483648,194 0x80000000 );195testcases[tc++] = new TestCase( SECTION,196 "0xffffffff",197 4294967295,198 0xffffffff );199testcases[tc++] = new TestCase( SECTION,200 "0x100000000",201 4294967296,202 0x100000000 );203testcases[tc++] = new TestCase( SECTION,204 "077777777777777777",205 2251799813685247,206 077777777777777777 );207testcases[tc++] = new TestCase( SECTION,208 "077777777777777776",209 2251799813685246,210 077777777777777776 );211testcases[tc++] = new TestCase( SECTION,212 "0x1fffffffffffff",213 9007199254740991,214 0x1fffffffffffff );215testcases[tc++] = new TestCase( SECTION,216 "0x20000000000000",217 9007199254740992,218 0x20000000000000 );219testcases[tc++] = new TestCase( SECTION,220 "0x20123456789abc",221 9027215253084860,222 0x20123456789abc );223testcases[tc++] = new TestCase( SECTION,224 "0x20123456789abd",225 9027215253084860,226 0x20123456789abd );227testcases[tc++] = new TestCase( SECTION,228 "0x20123456789abe",229 9027215253084862,230 0x20123456789abe );231testcases[tc++] = new TestCase( SECTION,232 "0x20123456789abf",233 9027215253084864,234 0x20123456789abf );235/***** These test the round-to-nearest-or-even-if-equally-close rule *****/236testcases[tc++] = new TestCase( SECTION,237 "0x1000000000000080",238 1152921504606847000,239 0x1000000000000080 );240testcases[tc++] = new TestCase( SECTION,241 "0x1000000000000081",242 1152921504606847200,243 0x1000000000000081 );244testcases[tc++] = new TestCase( SECTION,245 "0x1000000000000100",246 1152921504606847200,247 0x1000000000000100 );248testcases[tc++] = new TestCase( SECTION,249 "0x100000000000017f",250 1152921504606847200,251 0x100000000000017f );252testcases[tc++] = new TestCase( SECTION,253 "0x1000000000000180",254 1152921504606847500,255 0x1000000000000180 );256testcases[tc++] = new TestCase( SECTION,257 "0x1000000000000181",258 1152921504606847500,259 0x1000000000000181 );260testcases[tc++] = new TestCase( SECTION,261 "0x10000000000001f0",262 1152921504606847500,263 0x10000000000001f0 );264testcases[tc++] = new TestCase( SECTION,265 "0x1000000000000200",266 1152921504606847500,267 0x1000000000000200 );268testcases[tc++] = new TestCase( SECTION,269 "0x100000000000027f",270 1152921504606847500,271 0x100000000000027f );272testcases[tc++] = new TestCase( SECTION,273 "0x1000000000000280",274 1152921504606847500,275 0x1000000000000280 );276testcases[tc++] = new TestCase( SECTION,277 "0x1000000000000281",278 1152921504606847700,279 0x1000000000000281 );280testcases[tc++] = new TestCase( SECTION,281 "0x10000000000002ff",282 1152921504606847700,283 0x10000000000002ff );284testcases[tc++] = new TestCase( SECTION,285 "0x1000000000000300",286 1152921504606847700,287 0x1000000000000300 );288testcases[tc++] = new TestCase( SECTION,289 "0x10000000000000000",290 18446744073709552000,291 0x10000000000000000 );292testcases[tc++] = new TestCase( SECTION,293"parseInt(\"000000100000000100100011010001010110011110001001101010111100\",2)",2949027215253084860,295parseInt("000000100000000100100011010001010110011110001001101010111100",2) );296testcases[tc++] = new TestCase( SECTION,297"parseInt(\"000000100000000100100011010001010110011110001001101010111101\",2)",2989027215253084860,299parseInt("000000100000000100100011010001010110011110001001101010111101",2) );300testcases[tc++] = new TestCase( SECTION,301"parseInt(\"000000100000000100100011010001010110011110001001101010111111\",2)",3029027215253084864,303parseInt("000000100000000100100011010001010110011110001001101010111111",2) );304testcases[tc++] = new TestCase( SECTION,305"parseInt(\"0000001000000001001000110100010101100111100010011010101111010\",2)",30618054430506169720,307parseInt("0000001000000001001000110100010101100111100010011010101111010",2));308testcases[tc++] = new TestCase( SECTION,309"parseInt(\"0000001000000001001000110100010101100111100010011010101111011\",2)",31018054430506169724,311parseInt("0000001000000001001000110100010101100111100010011010101111011",2) );312testcases[tc++] = new TestCase( SECTION,313"parseInt(\"0000001000000001001000110100010101100111100010011010101111100\",2)",31418054430506169724,315parseInt("0000001000000001001000110100010101100111100010011010101111100",2));316testcases[tc++] = new TestCase( SECTION,317"parseInt(\"0000001000000001001000110100010101100111100010011010101111110\",2)",31818054430506169728,319parseInt("0000001000000001001000110100010101100111100010011010101111110",2));320testcases[tc++] = new TestCase( SECTION,321 "parseInt(\"yz\",35)",322 34,323 parseInt("yz",35) );324testcases[tc++] = new TestCase( SECTION,325 "parseInt(\"yz\",36)",326 1259,327 parseInt("yz",36) );328testcases[tc++] = new TestCase( SECTION,329 "parseInt(\"yz\",37)",330 NaN,331 parseInt("yz",37) );332testcases[tc++] = new TestCase( SECTION,333 "parseInt(\"+77\")",334 77,335 parseInt("+77") );336testcases[tc++] = new TestCase( SECTION,337 "parseInt(\"-77\",9)",338 -70,339 parseInt("-77",9) );340testcases[tc++] = new TestCase( SECTION,341 "parseInt(\"\\u20001234\\u2000\")",342 1234,343 parseInt("\u20001234\u2000") );344testcases[tc++] = new TestCase( SECTION,345 "parseInt(\"123456789012345678\")",346 123456789012345680,347 parseInt("123456789012345678") );348testcases[tc++] = new TestCase( SECTION,349 "parseInt(\"9\",8)",350 NaN,351 parseInt("9",8) );352testcases[tc++] = new TestCase( SECTION,353 "parseInt(\"1e2\")",354 1,355 parseInt("1e2") );356testcases[tc++] = new TestCase( SECTION,357 "parseInt(\"1.9999999999999999999\")",358 1,359 parseInt("1.9999999999999999999") );360testcases[tc++] = new TestCase( SECTION,361 "parseInt(\"0x10\")",362 16,363 parseInt("0x10") );364testcases[tc++] = new TestCase( SECTION,365 "parseInt(\"0x10\",10)",366 0,367 parseInt("0x10",10) );368testcases[tc++] = new TestCase( SECTION,369 "parseInt(\"0022\")",370 18,371 parseInt("0022") );372testcases[tc++] = new TestCase( SECTION,373 "parseInt(\"0022\",10)",374 22,375 parseInt("0022",10) );376testcases[tc++] = new TestCase( SECTION,377 "parseInt(\"0x1000000000000080\")",378 1152921504606847000,379 parseInt("0x1000000000000080") );380testcases[tc++] = new TestCase( SECTION,381 "parseInt(\"0x1000000000000081\")",382 1152921504606847200,383 parseInt("0x1000000000000081") );384s =385"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";386testcases[tc++] = new TestCase( SECTION, "s = "+387"\"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+388"s",389"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",390s );391testcases[tc++] = new TestCase( SECTION, "s +="+392"\"0000000000000000000000000000000000000\"; s",393"0xFFFFFFFFFFFFF800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",394s += "0000000000000000000000000000000000000" );395testcases[tc++] = new TestCase( SECTION, "-s",396-1.7976931348623157e+308,397-s );398s =399"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";400testcases[tc++] = new TestCase( SECTION, "s ="+401"\"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+402"s",403"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",404s );405testcases[tc++] = new TestCase( SECTION,406"s += \"0000000000000000000000000000000000001\"",407"0xFFFFFFFFFFFFF800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",408s += "0000000000000000000000000000000000001" );409testcases[tc++] = new TestCase( SECTION,410"-s",411-1.7976931348623157e+308,412-s );413s =414"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";415testcases[tc++] = new TestCase( SECTION,416"s ="+417"\"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+418"s",419"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",420s );421testcases[tc++] = new TestCase( SECTION,422"s += \"0000000000000000000000000000000000000\"",423"0xFFFFFFFFFFFFFC00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",424s += "0000000000000000000000000000000000000");425testcases[tc++] = new TestCase( SECTION,426"-s",427-Infinity,428-s );429s =430"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";431testcases[tc++] = new TestCase( SECTION,432"s = "+433"\"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";s",434"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",435s);436testcases[tc++] = new TestCase( SECTION,437"s += \"0000000000000000000000000000000000001\"",438"0xFFFFFFFFFFFFFB00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",439s += "0000000000000000000000000000000000001" );440testcases[tc++] = new TestCase( SECTION,441"-s",442-1.7976931348623157e+308,443-s );444testcases[tc++] = new TestCase( SECTION,445"s += \"0\"",446"0xFFFFFFFFFFFFFB000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010",447s += "0" );448testcases[tc++] = new TestCase( SECTION,449"-s",450-Infinity,451-s );452testcases[tc++] = new TestCase( SECTION,453"parseInt(s)",454Infinity,455parseInt(s) );456testcases[tc++] = new TestCase( SECTION,457"parseInt(s,32)",4580,459parseInt(s,32) );460testcases[tc++] = new TestCase( SECTION,461"parseInt(s,36)",462Infinity,463parseInt(s,36) );464testcases[tc++] = new TestCase( SECTION,465 "-\"\"",466 0,467 -"" );468testcases[tc++] = new TestCase( SECTION,469 "-\" \"",470 0,471 -" " );472testcases[tc++] = new TestCase( SECTION,473 "-\"999\"",474 -999,475 -"999" );476testcases[tc++] = new TestCase( SECTION,477 "-\" 999\"",478 -999,479 -" 999" );480testcases[tc++] = new TestCase( SECTION,481 "-\"\\t999\"",482 -999,483 -"\t999" );484testcases[tc++] = new TestCase( SECTION,485 "-\"013 \"",486 -13,487 -"013 " );488testcases[tc++] = new TestCase( SECTION,489 "-\"999\\t\"",490 -999,491 -"999\t" );492testcases[tc++] = new TestCase( SECTION,493 "-\"-Infinity\"",494 Infinity,495 -"-Infinity" );496testcases[tc++] = new TestCase( SECTION,497 "-\"-infinity\"",498 NaN,499 -"-infinity" );500testcases[tc++] = new TestCase( SECTION,501 "-\"+Infinity\"",502 -Infinity,503 -"+Infinity" );504testcases[tc++] = new TestCase( SECTION,505 "-\"+Infiniti\"",506 NaN,507 -"+Infiniti" );508testcases[tc++] = new TestCase( SECTION,509 "- -\"0x80000000\"",510 2147483648,511 - -"0x80000000" );512testcases[tc++] = new TestCase( SECTION,513 "- -\"0x100000000\"",514 4294967296,515 - -"0x100000000" );516testcases[tc++] = new TestCase( SECTION,517 "- \"-0x123456789abcde8\"",518 81985529216486880,519 - "-0x123456789abcde8" );520// the following two tests are not strictly ECMA 1.0521testcases[tc++] = new TestCase( SECTION,522 "-\"\\u20001234\\u2001\"",523 -1234,524 -"\u20001234\u2001" );525testcases[tc++] = new TestCase( SECTION,526 "-\"\\u20001234\\0\"",527 NaN,528 -"\u20001234\0" );529testcases[tc++] = new TestCase( SECTION,530 "-\"0x10\"",531 -16,532 -"0x10" );533testcases[tc++] = new TestCase( SECTION,534 "-\"+\"",535 NaN,536 -"+" );537testcases[tc++] = new TestCase( SECTION,538 "-\"-\"",539 NaN,540 -"-" );541testcases[tc++] = new TestCase( SECTION,542 "-\"-0-\"",543 NaN,544 -"-0-" );545testcases[tc++] = new TestCase( SECTION,546 "-\"1e-\"",547 NaN,548 -"1e-" );549testcases[tc++] = new TestCase( SECTION,550 "-\"1e-1\"",551 -0.1,552 -"1e-1" );553test();554function test(){555 for ( tc=0; tc < testcases.length; tc++ ) {556 testcases[tc].passed = writeTestCaseResult(557 testcases[tc].expect,558 testcases[tc].actual,559 testcases[tc].description +" = "+560 testcases[tc].actual );561 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";562 }563 stopTest();564 return ( testcases );...

Full Screen

Full Screen

9.3.1-1.js

Source:9.3.1-1.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 9.3.1-1.js24 ECMA Section: 9.3 Type Conversion: ToNumber25 Description: rules for converting an argument to a number.26 see 9.3.1 for cases for converting strings to numbers.27 special cases:28 undefined NaN29 Null NaN30 Boolean 1 if true; +0 if false31 Number the argument ( no conversion )32 String see test 9.3.133 Object see test 9.3-134 This tests ToNumber applied to the string type35 Author: christine@netscape.com36 Date: 10 july 199737*/38 var SECTION = "9.3.1-1";39 var VERSION = "ECMA_1";40 startTest();41 var TITLE = "ToNumber applied to the String type";42 var BUGNUMBER="77391";43 writeHeaderToLog( SECTION + " "+ TITLE);44 var testcases = getTestCases();45 test();46function test() {47 for ( tc=0; tc < testcases.length; tc++ ) {48 testcases[tc].passed = writeTestCaseResult(49 testcases[tc].expect,50 testcases[tc].actual,51 testcases[tc].description +" = "+52 testcases[tc].actual );53 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";54 }55 stopTest();56 return ( testcases );57}58function getTestCases() {59 var array = new Array();60 var item = 0;61 // StringNumericLiteral:::StrWhiteSpace:::StrWhiteSpaceChar StrWhiteSpace:::62 //63 // Name Unicode Value Escape Sequence64 // <TAB> 0X0009 \t65 // <SP> 0X002066 // <FF> 0X000C \f67 // <VT> 0X000B68 // <CR> 0X000D \r69 // <LF> 0X000A \n70 array[item++] = new TestCase( SECTION, "Number('')", 0, Number("") );71 array[item++] = new TestCase( SECTION, "Number(' ')", 0, Number(" ") );72 array[item++] = new TestCase( SECTION, "Number(\\t)", 0, Number("\t") );73 array[item++] = new TestCase( SECTION, "Number(\\n)", 0, Number("\n") );74 array[item++] = new TestCase( SECTION, "Number(\\r)", 0, Number("\r") );75 array[item++] = new TestCase( SECTION, "Number(\\f)", 0, Number("\f") );76 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x0009)", 0, Number(String.fromCharCode(0x0009)) );77 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x0020)", 0, Number(String.fromCharCode(0x0020)) );78 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x000C)", 0, Number(String.fromCharCode(0x000C)) );79 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x000B)", 0, Number(String.fromCharCode(0x000B)) );80 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x000D)", 0, Number(String.fromCharCode(0x000D)) );81 array[item++] = new TestCase( SECTION, "Number(String.fromCharCode(0x000A)", 0, Number(String.fromCharCode(0x000A)) );82 // a StringNumericLiteral may be preceeded or followed by whitespace and/or83 // line terminators84 array[item++] = new TestCase( SECTION, "Number( ' ' + 999 )", 999, Number( ' '+999) );85 array[item++] = new TestCase( SECTION, "Number( '\\n' + 999 )", 999, Number( '\n' +999) );86 array[item++] = new TestCase( SECTION, "Number( '\\r' + 999 )", 999, Number( '\r' +999) );87 array[item++] = new TestCase( SECTION, "Number( '\\t' + 999 )", 999, Number( '\t' +999) );88 array[item++] = new TestCase( SECTION, "Number( '\\f' + 999 )", 999, Number( '\f' +999) );89 array[item++] = new TestCase( SECTION, "Number( 999 + ' ' )", 999, Number( 999+' ') );90 array[item++] = new TestCase( SECTION, "Number( 999 + '\\n' )", 999, Number( 999+'\n' ) );91 array[item++] = new TestCase( SECTION, "Number( 999 + '\\r' )", 999, Number( 999+'\r' ) );92 array[item++] = new TestCase( SECTION, "Number( 999 + '\\t' )", 999, Number( 999+'\t' ) );93 array[item++] = new TestCase( SECTION, "Number( 999 + '\\f' )", 999, Number( 999+'\f' ) );94 array[item++] = new TestCase( SECTION, "Number( '\\n' + 999 + '\\n' )", 999, Number( '\n' +999+'\n' ) );95 array[item++] = new TestCase( SECTION, "Number( '\\r' + 999 + '\\r' )", 999, Number( '\r' +999+'\r' ) );96 array[item++] = new TestCase( SECTION, "Number( '\\t' + 999 + '\\t' )", 999, Number( '\t' +999+'\t' ) );97 array[item++] = new TestCase( SECTION, "Number( '\\f' + 999 + '\\f' )", 999, Number( '\f' +999+'\f' ) );98 array[item++] = new TestCase( SECTION, "Number( ' ' + '999' )", 999, Number( ' '+'999') );99 array[item++] = new TestCase( SECTION, "Number( '\\n' + '999' )", 999, Number( '\n' +'999') );100 array[item++] = new TestCase( SECTION, "Number( '\\r' + '999' )", 999, Number( '\r' +'999') );101 array[item++] = new TestCase( SECTION, "Number( '\\t' + '999' )", 999, Number( '\t' +'999') );102 array[item++] = new TestCase( SECTION, "Number( '\\f' + '999' )", 999, Number( '\f' +'999') );103 array[item++] = new TestCase( SECTION, "Number( '999' + ' ' )", 999, Number( '999'+' ') );104 array[item++] = new TestCase( SECTION, "Number( '999' + '\\n' )", 999, Number( '999'+'\n' ) );105 array[item++] = new TestCase( SECTION, "Number( '999' + '\\r' )", 999, Number( '999'+'\r' ) );106 array[item++] = new TestCase( SECTION, "Number( '999' + '\\t' )", 999, Number( '999'+'\t' ) );107 array[item++] = new TestCase( SECTION, "Number( '999' + '\\f' )", 999, Number( '999'+'\f' ) );108 array[item++] = new TestCase( SECTION, "Number( '\\n' + '999' + '\\n' )", 999, Number( '\n' +'999'+'\n' ) );109 array[item++] = new TestCase( SECTION, "Number( '\\r' + '999' + '\\r' )", 999, Number( '\r' +'999'+'\r' ) );110 array[item++] = new TestCase( SECTION, "Number( '\\t' + '999' + '\\t' )", 999, Number( '\t' +'999'+'\t' ) );111 array[item++] = new TestCase( SECTION, "Number( '\\f' + '999' + '\\f' )", 999, Number( '\f' +'999'+'\f' ) );112 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0009) + '99' )", 99, Number( String.fromCharCode(0x0009) + '99' ) );113 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0020) + '99' )", 99, Number( String.fromCharCode(0x0020) + '99' ) );114 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000C) + '99' )", 99, Number( String.fromCharCode(0x000C) + '99' ) );115 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000B) + '99' )", 99, Number( String.fromCharCode(0x000B) + '99' ) );116 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000D) + '99' )", 99, Number( String.fromCharCode(0x000D) + '99' ) );117 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000A) + '99' )", 99, Number( String.fromCharCode(0x000A) + '99' ) );118 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)) );119 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0020) + '99' + String.fromCharCode(0x0020)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0020)) );120 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000C) + '99' + String.fromCharCode(0x000C)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000C)) );121 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000D) + '99' + String.fromCharCode(0x000D)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000D)) );122 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000B) + '99' + String.fromCharCode(0x000B)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000B)) );123 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000A) + '99' + String.fromCharCode(0x000A)", 99, Number( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000A)) );124 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x0009)", 99, Number( '99' + String.fromCharCode(0x0009)) );125 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x0020)", 99, Number( '99' + String.fromCharCode(0x0020)) );126 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x000C)", 99, Number( '99' + String.fromCharCode(0x000C)) );127 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x000D)", 99, Number( '99' + String.fromCharCode(0x000D)) );128 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x000B)", 99, Number( '99' + String.fromCharCode(0x000B)) );129 array[item++] = new TestCase( SECTION, "Number( '99' + String.fromCharCode(0x000A)", 99, Number( '99' + String.fromCharCode(0x000A)) );130 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0009) + 99 )", 99, Number( String.fromCharCode(0x0009) + 99 ) );131 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0020) + 99 )", 99, Number( String.fromCharCode(0x0020) + 99 ) );132 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000C) + 99 )", 99, Number( String.fromCharCode(0x000C) + 99 ) );133 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000B) + 99 )", 99, Number( String.fromCharCode(0x000B) + 99 ) );134 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000D) + 99 )", 99, Number( String.fromCharCode(0x000D) + 99 ) );135 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000A) + 99 )", 99, Number( String.fromCharCode(0x000A) + 99 ) );136 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)) );137 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x0020) + 99 + String.fromCharCode(0x0020)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0020)) );138 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000C) + 99 + String.fromCharCode(0x000C)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000C)) );139 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000D) + 99 + String.fromCharCode(0x000D)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000D)) );140 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000B) + 99 + String.fromCharCode(0x000B)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000B)) );141 array[item++] = new TestCase( SECTION, "Number( String.fromCharCode(0x000A) + 99 + String.fromCharCode(0x000A)", 99, Number( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000A)) );142 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x0009)", 99, Number( 99 + String.fromCharCode(0x0009)) );143 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x0020)", 99, Number( 99 + String.fromCharCode(0x0020)) );144 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x000C)", 99, Number( 99 + String.fromCharCode(0x000C)) );145 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x000D)", 99, Number( 99 + String.fromCharCode(0x000D)) );146 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x000B)", 99, Number( 99 + String.fromCharCode(0x000B)) );147 array[item++] = new TestCase( SECTION, "Number( 99 + String.fromCharCode(0x000A)", 99, Number( 99 + String.fromCharCode(0x000A)) );148 // StrNumericLiteral:::StrDecimalLiteral:::Infinity149 array[item++] = new TestCase( SECTION, "Number('Infinity')", Math.pow(10,10000), Number("Infinity") );150 array[item++] = new TestCase( SECTION, "Number('-Infinity')", -Math.pow(10,10000), Number("-Infinity") );151 array[item++] = new TestCase( SECTION, "Number('+Infinity')", Math.pow(10,10000), Number("+Infinity") );152 // StrNumericLiteral::: StrDecimalLiteral ::: DecimalDigits . DecimalDigits opt ExponentPart opt153 array[item++] = new TestCase( SECTION, "Number('0')", 0, Number("0") );154 array[item++] = new TestCase( SECTION, "Number('-0')", -0, Number("-0") );155 array[item++] = new TestCase( SECTION, "Number('+0')", 0, Number("+0") );156 array[item++] = new TestCase( SECTION, "Number('1')", 1, Number("1") );157 array[item++] = new TestCase( SECTION, "Number('-1')", -1, Number("-1") );158 array[item++] = new TestCase( SECTION, "Number('+1')", 1, Number("+1") );159 array[item++] = new TestCase( SECTION, "Number('2')", 2, Number("2") );160 array[item++] = new TestCase( SECTION, "Number('-2')", -2, Number("-2") );161 array[item++] = new TestCase( SECTION, "Number('+2')", 2, Number("+2") );162 array[item++] = new TestCase( SECTION, "Number('3')", 3, Number("3") );163 array[item++] = new TestCase( SECTION, "Number('-3')", -3, Number("-3") );164 array[item++] = new TestCase( SECTION, "Number('+3')", 3, Number("+3") );165 array[item++] = new TestCase( SECTION, "Number('4')", 4, Number("4") );166 array[item++] = new TestCase( SECTION, "Number('-4')", -4, Number("-4") );167 array[item++] = new TestCase( SECTION, "Number('+4')", 4, Number("+4") );168 array[item++] = new TestCase( SECTION, "Number('5')", 5, Number("5") );169 array[item++] = new TestCase( SECTION, "Number('-5')", -5, Number("-5") );170 array[item++] = new TestCase( SECTION, "Number('+5')", 5, Number("+5") );171 array[item++] = new TestCase( SECTION, "Number('6')", 6, Number("6") );172 array[item++] = new TestCase( SECTION, "Number('-6')", -6, Number("-6") );173 array[item++] = new TestCase( SECTION, "Number('+6')", 6, Number("+6") );174 array[item++] = new TestCase( SECTION, "Number('7')", 7, Number("7") );175 array[item++] = new TestCase( SECTION, "Number('-7')", -7, Number("-7") );176 array[item++] = new TestCase( SECTION, "Number('+7')", 7, Number("+7") );177 array[item++] = new TestCase( SECTION, "Number('8')", 8, Number("8") );178 array[item++] = new TestCase( SECTION, "Number('-8')", -8, Number("-8") );179 array[item++] = new TestCase( SECTION, "Number('+8')", 8, Number("+8") );180 array[item++] = new TestCase( SECTION, "Number('9')", 9, Number("9") );181 array[item++] = new TestCase( SECTION, "Number('-9')", -9, Number("-9") );182 array[item++] = new TestCase( SECTION, "Number('+9')", 9, Number("+9") );183 array[item++] = new TestCase( SECTION, "Number('3.14159')", 3.14159, Number("3.14159") );184 array[item++] = new TestCase( SECTION, "Number('-3.14159')", -3.14159, Number("-3.14159") );185 array[item++] = new TestCase( SECTION, "Number('+3.14159')", 3.14159, Number("+3.14159") );186 array[item++] = new TestCase( SECTION, "Number('3.')", 3, Number("3.") );187 array[item++] = new TestCase( SECTION, "Number('-3.')", -3, Number("-3.") );188 array[item++] = new TestCase( SECTION, "Number('+3.')", 3, Number("+3.") );189 array[item++] = new TestCase( SECTION, "Number('3.e1')", 30, Number("3.e1") );190 array[item++] = new TestCase( SECTION, "Number('-3.e1')", -30, Number("-3.e1") );191 array[item++] = new TestCase( SECTION, "Number('+3.e1')", 30, Number("+3.e1") );192 array[item++] = new TestCase( SECTION, "Number('3.e+1')", 30, Number("3.e+1") );193 array[item++] = new TestCase( SECTION, "Number('-3.e+1')", -30, Number("-3.e+1") );194 array[item++] = new TestCase( SECTION, "Number('+3.e+1')", 30, Number("+3.e+1") );195 array[item++] = new TestCase( SECTION, "Number('3.e-1')", .30, Number("3.e-1") );196 array[item++] = new TestCase( SECTION, "Number('-3.e-1')", -.30, Number("-3.e-1") );197 array[item++] = new TestCase( SECTION, "Number('+3.e-1')", .30, Number("+3.e-1") );198 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt199 array[item++] = new TestCase( SECTION, "Number('.00001')", 0.00001, Number(".00001") );200 array[item++] = new TestCase( SECTION, "Number('+.00001')", 0.00001, Number("+.00001") );201 array[item++] = new TestCase( SECTION, "Number('-0.0001')", -0.00001, Number("-.00001") );202 array[item++] = new TestCase( SECTION, "Number('.01e2')", 1, Number(".01e2") );203 array[item++] = new TestCase( SECTION, "Number('+.01e2')", 1, Number("+.01e2") );204 array[item++] = new TestCase( SECTION, "Number('-.01e2')", -1, Number("-.01e2") );205 array[item++] = new TestCase( SECTION, "Number('.01e+2')", 1, Number(".01e+2") );206 array[item++] = new TestCase( SECTION, "Number('+.01e+2')", 1, Number("+.01e+2") );207 array[item++] = new TestCase( SECTION, "Number('-.01e+2')", -1, Number("-.01e+2") );208 array[item++] = new TestCase( SECTION, "Number('.01e-2')", 0.0001, Number(".01e-2") );209 array[item++] = new TestCase( SECTION, "Number('+.01e-2')", 0.0001, Number("+.01e-2") );210 array[item++] = new TestCase( SECTION, "Number('-.01e-2')", -0.0001, Number("-.01e-2") );211 // StrDecimalLiteral::: DecimalDigits ExponentPart opt212 array[item++] = new TestCase( SECTION, "Number('1234e5')", 123400000, Number("1234e5") );213 array[item++] = new TestCase( SECTION, "Number('+1234e5')", 123400000, Number("+1234e5") );214 array[item++] = new TestCase( SECTION, "Number('-1234e5')", -123400000, Number("-1234e5") );215 array[item++] = new TestCase( SECTION, "Number('1234e+5')", 123400000, Number("1234e+5") );216 array[item++] = new TestCase( SECTION, "Number('+1234e+5')", 123400000, Number("+1234e+5") );217 array[item++] = new TestCase( SECTION, "Number('-1234e+5')", -123400000, Number("-1234e+5") );218 array[item++] = new TestCase( SECTION, "Number('1234e-5')", 0.01234, Number("1234e-5") );219 array[item++] = new TestCase( SECTION, "Number('+1234e-5')", 0.01234, Number("+1234e-5") );220 array[item++] = new TestCase( SECTION, "Number('-1234e-5')", -0.01234, Number("-1234e-5") );221 // StrNumericLiteral::: HexIntegerLiteral222 array[item++] = new TestCase( SECTION, "Number('0x0')", 0, Number("0x0"));223 array[item++] = new TestCase( SECTION, "Number('0x1')", 1, Number("0x1"));224 array[item++] = new TestCase( SECTION, "Number('0x2')", 2, Number("0x2"));225 array[item++] = new TestCase( SECTION, "Number('0x3')", 3, Number("0x3"));226 array[item++] = new TestCase( SECTION, "Number('0x4')", 4, Number("0x4"));227 array[item++] = new TestCase( SECTION, "Number('0x5')", 5, Number("0x5"));228 array[item++] = new TestCase( SECTION, "Number('0x6')", 6, Number("0x6"));229 array[item++] = new TestCase( SECTION, "Number('0x7')", 7, Number("0x7"));230 array[item++] = new TestCase( SECTION, "Number('0x8')", 8, Number("0x8"));231 array[item++] = new TestCase( SECTION, "Number('0x9')", 9, Number("0x9"));232 array[item++] = new TestCase( SECTION, "Number('0xa')", 10, Number("0xa"));233 array[item++] = new TestCase( SECTION, "Number('0xb')", 11, Number("0xb"));234 array[item++] = new TestCase( SECTION, "Number('0xc')", 12, Number("0xc"));235 array[item++] = new TestCase( SECTION, "Number('0xd')", 13, Number("0xd"));236 array[item++] = new TestCase( SECTION, "Number('0xe')", 14, Number("0xe"));237 array[item++] = new TestCase( SECTION, "Number('0xf')", 15, Number("0xf"));238 array[item++] = new TestCase( SECTION, "Number('0xA')", 10, Number("0xA"));239 array[item++] = new TestCase( SECTION, "Number('0xB')", 11, Number("0xB"));240 array[item++] = new TestCase( SECTION, "Number('0xC')", 12, Number("0xC"));241 array[item++] = new TestCase( SECTION, "Number('0xD')", 13, Number("0xD"));242 array[item++] = new TestCase( SECTION, "Number('0xE')", 14, Number("0xE"));243 array[item++] = new TestCase( SECTION, "Number('0xF')", 15, Number("0xF"));244 array[item++] = new TestCase( SECTION, "Number('0X0')", 0, Number("0X0"));245 array[item++] = new TestCase( SECTION, "Number('0X1')", 1, Number("0X1"));246 array[item++] = new TestCase( SECTION, "Number('0X2')", 2, Number("0X2"));247 array[item++] = new TestCase( SECTION, "Number('0X3')", 3, Number("0X3"));248 array[item++] = new TestCase( SECTION, "Number('0X4')", 4, Number("0X4"));249 array[item++] = new TestCase( SECTION, "Number('0X5')", 5, Number("0X5"));250 array[item++] = new TestCase( SECTION, "Number('0X6')", 6, Number("0X6"));251 array[item++] = new TestCase( SECTION, "Number('0X7')", 7, Number("0X7"));252 array[item++] = new TestCase( SECTION, "Number('0X8')", 8, Number("0X8"));253 array[item++] = new TestCase( SECTION, "Number('0X9')", 9, Number("0X9"));254 array[item++] = new TestCase( SECTION, "Number('0Xa')", 10, Number("0Xa"));255 array[item++] = new TestCase( SECTION, "Number('0Xb')", 11, Number("0Xb"));256 array[item++] = new TestCase( SECTION, "Number('0Xc')", 12, Number("0Xc"));257 array[item++] = new TestCase( SECTION, "Number('0Xd')", 13, Number("0Xd"));258 array[item++] = new TestCase( SECTION, "Number('0Xe')", 14, Number("0Xe"));259 array[item++] = new TestCase( SECTION, "Number('0Xf')", 15, Number("0Xf"));260 array[item++] = new TestCase( SECTION, "Number('0XA')", 10, Number("0XA"));261 array[item++] = new TestCase( SECTION, "Number('0XB')", 11, Number("0XB"));262 array[item++] = new TestCase( SECTION, "Number('0XC')", 12, Number("0XC"));263 array[item++] = new TestCase( SECTION, "Number('0XD')", 13, Number("0XD"));264 array[item++] = new TestCase( SECTION, "Number('0XE')", 14, Number("0XE"));265 array[item++] = new TestCase( SECTION, "Number('0XF')", 15, Number("0XF"));266 return ( array );...

Full Screen

Full Screen

15.1.2.3-2.js

Source:15.1.2.3-2.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 15.1.2.3-2.js24 ECMA Section: 15.1.2.3 Function properties of the global object:25 parseFloat( string )26 Description: The parseFloat function produces a number value dictated27 by the interpretation of the contents of the string28 argument defined as a decimal literal.29 When the parseFloat function is called, the following30 steps are taken:31 1. Call ToString( string ).32 2. Remove leading whitespace Result(1).33 3. If neither Result(2) nor any prefix of Result(2)34 satisfies the syntax of a StrDecimalLiteral,35 return NaN.36 4. Compute the longest prefix of Result(2) which might37 be Resusult(2) itself, that satisfies the syntax of38 a StrDecimalLiteral39 5. Return the number value for the MV of Result(4).40 Note that parseFloate may interpret only a leading41 portion of the string as a number value; it ignores any42 characters that cannot be interpreted as part of the43 notation of a decimal literal, and no indication is given44 that such characters were ignored.45 StrDecimalLiteral::46 Infinity47 DecimalDigits.DecimalDigits opt ExponentPart opt48 .DecimalDigits ExponentPart opt49 DecimalDigits ExponentPart opt50 Author: christine@netscape.com51 Date: 28 october 199752*/53 var SECTION = "15.1.2.3-2";54 var VERSION = "ECMA_1";55 startTest();56 var BUGNUMBER = "77391";57 var testcases = getTestCases();58 writeHeaderToLog( SECTION + " parseFloat(string)");59 test();60function getTestCases() {61 var array = new Array();62 var item = 0;63 array[item++] = new TestCase( SECTION, "parseFloat(true)", Number.NaN, parseFloat(true) );64 array[item++] = new TestCase( SECTION, "parseFloat(false)", Number.NaN, parseFloat(false) );65 array[item++] = new TestCase( SECTION, "parseFloat('string')", Number.NaN, parseFloat("string") );66 array[item++] = new TestCase( SECTION, "parseFloat(' Infinity')", Number.POSITIVE_INFINITY, parseFloat("Infinity") );67// array[item++] = new TestCase( SECTION, "parseFloat(Infinity)", Number.POSITIVE_INFINITY, parseFloat(Infinity) );68 array[item++] = new TestCase( SECTION, "parseFloat(' 0')", 0, parseFloat(" 0") );69 array[item++] = new TestCase( SECTION, "parseFloat(' -0')", -0, parseFloat(" -0") );70 array[item++] = new TestCase( SECTION, "parseFloat(' +0')", 0, parseFloat(" +0") );71 array[item++] = new TestCase( SECTION, "parseFloat(' 1')", 1, parseFloat(" 1") );72 array[item++] = new TestCase( SECTION, "parseFloat(' -1')", -1, parseFloat(" -1") );73 array[item++] = new TestCase( SECTION, "parseFloat(' +1')", 1, parseFloat(" +1") );74 array[item++] = new TestCase( SECTION, "parseFloat(' 2')", 2, parseFloat(" 2") );75 array[item++] = new TestCase( SECTION, "parseFloat(' -2')", -2, parseFloat(" -2") );76 array[item++] = new TestCase( SECTION, "parseFloat(' +2')", 2, parseFloat(" +2") );77 array[item++] = new TestCase( SECTION, "parseFloat(' 3')", 3, parseFloat(" 3") );78 array[item++] = new TestCase( SECTION, "parseFloat(' -3')", -3, parseFloat(" -3") );79 array[item++] = new TestCase( SECTION, "parseFloat(' +3')", 3, parseFloat(" +3") );80 array[item++] = new TestCase( SECTION, "parseFloat(' 4')", 4, parseFloat(" 4") );81 array[item++] = new TestCase( SECTION, "parseFloat(' -4')", -4, parseFloat(" -4") );82 array[item++] = new TestCase( SECTION, "parseFloat(' +4')", 4, parseFloat(" +4") );83 array[item++] = new TestCase( SECTION, "parseFloat(' 5')", 5, parseFloat(" 5") );84 array[item++] = new TestCase( SECTION, "parseFloat(' -5')", -5, parseFloat(" -5") );85 array[item++] = new TestCase( SECTION, "parseFloat(' +5')", 5, parseFloat(" +5") );86 array[item++] = new TestCase( SECTION, "parseFloat(' 6')", 6, parseFloat(" 6") );87 array[item++] = new TestCase( SECTION, "parseFloat(' -6')", -6, parseFloat(" -6") );88 array[item++] = new TestCase( SECTION, "parseFloat(' +6')", 6, parseFloat(" +6") );89 array[item++] = new TestCase( SECTION, "parseFloat(' 7')", 7, parseFloat(" 7") );90 array[item++] = new TestCase( SECTION, "parseFloat(' -7')", -7, parseFloat(" -7") );91 array[item++] = new TestCase( SECTION, "parseFloat(' +7')", 7, parseFloat(" +7") );92 array[item++] = new TestCase( SECTION, "parseFloat(' 8')", 8, parseFloat(" 8") );93 array[item++] = new TestCase( SECTION, "parseFloat(' -8')", -8, parseFloat(" -8") );94 array[item++] = new TestCase( SECTION, "parseFloat(' +8')", 8, parseFloat(" +8") );95 array[item++] = new TestCase( SECTION, "parseFloat(' 9')", 9, parseFloat(" 9") );96 array[item++] = new TestCase( SECTION, "parseFloat(' -9')", -9, parseFloat(" -9") );97 array[item++] = new TestCase( SECTION, "parseFloat(' +9')", 9, parseFloat(" +9") );98 array[item++] = new TestCase( SECTION, "parseFloat(' 3.14159')", 3.14159, parseFloat(" 3.14159") );99 array[item++] = new TestCase( SECTION, "parseFloat(' -3.14159')", -3.14159, parseFloat(" -3.14159") );100 array[item++] = new TestCase( SECTION, "parseFloat(' +3.14159')", 3.14159, parseFloat(" +3.14159") );101 array[item++] = new TestCase( SECTION, "parseFloat(' 3.')", 3, parseFloat(" 3.") );102 array[item++] = new TestCase( SECTION, "parseFloat(' -3.')", -3, parseFloat(" -3.") );103 array[item++] = new TestCase( SECTION, "parseFloat(' +3.')", 3, parseFloat(" +3.") );104 array[item++] = new TestCase( SECTION, "parseFloat(' 3.e1')", 30, parseFloat(" 3.e1") );105 array[item++] = new TestCase( SECTION, "parseFloat(' -3.e1')", -30, parseFloat(" -3.e1") );106 array[item++] = new TestCase( SECTION, "parseFloat(' +3.e1')", 30, parseFloat(" +3.e1") );107 array[item++] = new TestCase( SECTION, "parseFloat(' 3.e+1')", 30, parseFloat(" 3.e+1") );108 array[item++] = new TestCase( SECTION, "parseFloat(' -3.e+1')", -30, parseFloat(" -3.e+1") );109 array[item++] = new TestCase( SECTION, "parseFloat(' +3.e+1')", 30, parseFloat(" +3.e+1") );110 array[item++] = new TestCase( SECTION, "parseFloat(' 3.e-1')", .30, parseFloat(" 3.e-1") );111 array[item++] = new TestCase( SECTION, "parseFloat(' -3.e-1')", -.30, parseFloat(" -3.e-1") );112 array[item++] = new TestCase( SECTION, "parseFloat(' +3.e-1')", .30, parseFloat(" +3.e-1") );113 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt114 array[item++] = new TestCase( SECTION, "parseFloat(' .00001')", 0.00001, parseFloat(" .00001") );115 array[item++] = new TestCase( SECTION, "parseFloat(' +.00001')", 0.00001, parseFloat(" +.00001") );116 array[item++] = new TestCase( SECTION, "parseFloat(' -0.0001')", -0.00001, parseFloat(" -.00001") );117 array[item++] = new TestCase( SECTION, "parseFloat(' .01e2')", 1, parseFloat(" .01e2") );118 array[item++] = new TestCase( SECTION, "parseFloat(' +.01e2')", 1, parseFloat(" +.01e2") );119 array[item++] = new TestCase( SECTION, "parseFloat(' -.01e2')", -1, parseFloat(" -.01e2") );120 array[item++] = new TestCase( SECTION, "parseFloat(' .01e+2')", 1, parseFloat(" .01e+2") );121 array[item++] = new TestCase( SECTION, "parseFloat(' +.01e+2')", 1, parseFloat(" +.01e+2") );122 array[item++] = new TestCase( SECTION, "parseFloat(' -.01e+2')", -1, parseFloat(" -.01e+2") );123 array[item++] = new TestCase( SECTION, "parseFloat(' .01e-2')", 0.0001, parseFloat(" .01e-2") );124 array[item++] = new TestCase( SECTION, "parseFloat(' +.01e-2')", 0.0001, parseFloat(" +.01e-2") );125 array[item++] = new TestCase( SECTION, "parseFloat(' -.01e-2')", -0.0001, parseFloat(" -.01e-2") );126 // StrDecimalLiteral::: DecimalDigits ExponentPart opt127 array[item++] = new TestCase( SECTION, "parseFloat(' 1234e5')", 123400000, parseFloat(" 1234e5") );128 array[item++] = new TestCase( SECTION, "parseFloat(' +1234e5')", 123400000, parseFloat(" +1234e5") );129 array[item++] = new TestCase( SECTION, "parseFloat(' -1234e5')", -123400000, parseFloat(" -1234e5") );130 array[item++] = new TestCase( SECTION, "parseFloat(' 1234e+5')", 123400000, parseFloat(" 1234e+5") );131 array[item++] = new TestCase( SECTION, "parseFloat(' +1234e+5')", 123400000, parseFloat(" +1234e+5") );132 array[item++] = new TestCase( SECTION, "parseFloat(' -1234e+5')", -123400000, parseFloat(" -1234e+5") );133 array[item++] = new TestCase( SECTION, "parseFloat(' 1234e-5')", 0.01234, parseFloat(" 1234e-5") );134 array[item++] = new TestCase( SECTION, "parseFloat(' +1234e-5')", 0.01234, parseFloat(" +1234e-5") );135 array[item++] = new TestCase( SECTION, "parseFloat(' -1234e-5')", -0.01234, parseFloat(" -1234e-5") );136 array[item++] = new TestCase( SECTION, "parseFloat(' .01E2')", 1, parseFloat(" .01E2") );137 array[item++] = new TestCase( SECTION, "parseFloat(' +.01E2')", 1, parseFloat(" +.01E2") );138 array[item++] = new TestCase( SECTION, "parseFloat(' -.01E2')", -1, parseFloat(" -.01E2") );139 array[item++] = new TestCase( SECTION, "parseFloat(' .01E+2')", 1, parseFloat(" .01E+2") );140 array[item++] = new TestCase( SECTION, "parseFloat(' +.01E+2')", 1, parseFloat(" +.01E+2") );141 array[item++] = new TestCase( SECTION, "parseFloat(' -.01E+2')", -1, parseFloat(" -.01E+2") );142 array[item++] = new TestCase( SECTION, "parseFloat(' .01E-2')", 0.0001, parseFloat(" .01E-2") );143 array[item++] = new TestCase( SECTION, "parseFloat(' +.01E-2')", 0.0001, parseFloat(" +.01E-2") );144 array[item++] = new TestCase( SECTION, "parseFloat(' -.01E-2')", -0.0001, parseFloat(" -.01E-2") );145 // StrDecimalLiteral::: DecimalDigits ExponentPart opt146 array[item++] = new TestCase( SECTION, "parseFloat(' 1234E5')", 123400000, parseFloat(" 1234E5") );147 array[item++] = new TestCase( SECTION, "parseFloat(' +1234E5')", 123400000, parseFloat(" +1234E5") );148 array[item++] = new TestCase( SECTION, "parseFloat(' -1234E5')", -123400000, parseFloat(" -1234E5") );149 array[item++] = new TestCase( SECTION, "parseFloat(' 1234E+5')", 123400000, parseFloat(" 1234E+5") );150 array[item++] = new TestCase( SECTION, "parseFloat(' +1234E+5')", 123400000, parseFloat(" +1234E+5") );151 array[item++] = new TestCase( SECTION, "parseFloat(' -1234E+5')", -123400000, parseFloat(" -1234E+5") );152 array[item++] = new TestCase( SECTION, "parseFloat(' 1234E-5')", 0.01234, parseFloat(" 1234E-5") );153 array[item++] = new TestCase( SECTION, "parseFloat(' +1234E-5')", 0.01234, parseFloat(" +1234E-5") );154 array[item++] = new TestCase( SECTION, "parseFloat(' -1234E-5')", -0.01234, parseFloat(" -1234E-5") );155 // hex cases should all return NaN156 array[item++] = new TestCase( SECTION, "parseFloat(' 0x0')", 0, parseFloat(" 0x0"));157 array[item++] = new TestCase( SECTION, "parseFloat(' 0x1')", 0, parseFloat(" 0x1"));158 array[item++] = new TestCase( SECTION, "parseFloat(' 0x2')", 0, parseFloat(" 0x2"));159 array[item++] = new TestCase( SECTION, "parseFloat(' 0x3')", 0, parseFloat(" 0x3"));160 array[item++] = new TestCase( SECTION, "parseFloat(' 0x4')", 0, parseFloat(" 0x4"));161 array[item++] = new TestCase( SECTION, "parseFloat(' 0x5')", 0, parseFloat(" 0x5"));162 array[item++] = new TestCase( SECTION, "parseFloat(' 0x6')", 0, parseFloat(" 0x6"));163 array[item++] = new TestCase( SECTION, "parseFloat(' 0x7')", 0, parseFloat(" 0x7"));164 array[item++] = new TestCase( SECTION, "parseFloat(' 0x8')", 0, parseFloat(" 0x8"));165 array[item++] = new TestCase( SECTION, "parseFloat(' 0x9')", 0, parseFloat(" 0x9"));166 array[item++] = new TestCase( SECTION, "parseFloat(' 0xa')", 0, parseFloat(" 0xa"));167 array[item++] = new TestCase( SECTION, "parseFloat(' 0xb')", 0, parseFloat(" 0xb"));168 array[item++] = new TestCase( SECTION, "parseFloat(' 0xc')", 0, parseFloat(" 0xc"));169 array[item++] = new TestCase( SECTION, "parseFloat(' 0xd')", 0, parseFloat(" 0xd"));170 array[item++] = new TestCase( SECTION, "parseFloat(' 0xe')", 0, parseFloat(" 0xe"));171 array[item++] = new TestCase( SECTION, "parseFloat(' 0xf')", 0, parseFloat(" 0xf"));172 array[item++] = new TestCase( SECTION, "parseFloat(' 0xA')", 0, parseFloat(" 0xA"));173 array[item++] = new TestCase( SECTION, "parseFloat(' 0xB')", 0, parseFloat(" 0xB"));174 array[item++] = new TestCase( SECTION, "parseFloat(' 0xC')", 0, parseFloat(" 0xC"));175 array[item++] = new TestCase( SECTION, "parseFloat(' 0xD')", 0, parseFloat(" 0xD"));176 array[item++] = new TestCase( SECTION, "parseFloat(' 0xE')", 0, parseFloat(" 0xE"));177 array[item++] = new TestCase( SECTION, "parseFloat(' 0xF')", 0, parseFloat(" 0xF"));178 array[item++] = new TestCase( SECTION, "parseFloat(' 0X0')", 0, parseFloat(" 0X0"));179 array[item++] = new TestCase( SECTION, "parseFloat(' 0X1')", 0, parseFloat(" 0X1"));180 array[item++] = new TestCase( SECTION, "parseFloat(' 0X2')", 0, parseFloat(" 0X2"));181 array[item++] = new TestCase( SECTION, "parseFloat(' 0X3')", 0, parseFloat(" 0X3"));182 array[item++] = new TestCase( SECTION, "parseFloat(' 0X4')", 0, parseFloat(" 0X4"));183 array[item++] = new TestCase( SECTION, "parseFloat(' 0X5')", 0, parseFloat(" 0X5"));184 array[item++] = new TestCase( SECTION, "parseFloat(' 0X6')", 0, parseFloat(" 0X6"));185 array[item++] = new TestCase( SECTION, "parseFloat(' 0X7')", 0, parseFloat(" 0X7"));186 array[item++] = new TestCase( SECTION, "parseFloat(' 0X8')", 0, parseFloat(" 0X8"));187 array[item++] = new TestCase( SECTION, "parseFloat(' 0X9')", 0, parseFloat(" 0X9"));188 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xa')", 0, parseFloat(" 0Xa"));189 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xb')", 0, parseFloat(" 0Xb"));190 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xc')", 0, parseFloat(" 0Xc"));191 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xd')", 0, parseFloat(" 0Xd"));192 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xe')", 0, parseFloat(" 0Xe"));193 array[item++] = new TestCase( SECTION, "parseFloat(' 0Xf')", 0, parseFloat(" 0Xf"));194 array[item++] = new TestCase( SECTION, "parseFloat(' 0XA')", 0, parseFloat(" 0XA"));195 array[item++] = new TestCase( SECTION, "parseFloat(' 0XB')", 0, parseFloat(" 0XB"));196 array[item++] = new TestCase( SECTION, "parseFloat(' 0XC')", 0, parseFloat(" 0XC"));197 array[item++] = new TestCase( SECTION, "parseFloat(' 0XD')", 0, parseFloat(" 0XD"));198 array[item++] = new TestCase( SECTION, "parseFloat(' 0XE')", 0, parseFloat(" 0XE"));199 array[item++] = new TestCase( SECTION, "parseFloat(' 0XF')", 0, parseFloat(" 0XF"));200 // A StringNumericLiteral may not use octal notation201 array[item++] = new TestCase( SECTION, "parseFloat(' 00')", 0, parseFloat(" 00"));202 array[item++] = new TestCase( SECTION, "parseFloat(' 01')", 1, parseFloat(" 01"));203 array[item++] = new TestCase( SECTION, "parseFloat(' 02')", 2, parseFloat(" 02"));204 array[item++] = new TestCase( SECTION, "parseFloat(' 03')", 3, parseFloat(" 03"));205 array[item++] = new TestCase( SECTION, "parseFloat(' 04')", 4, parseFloat(" 04"));206 array[item++] = new TestCase( SECTION, "parseFloat(' 05')", 5, parseFloat(" 05"));207 array[item++] = new TestCase( SECTION, "parseFloat(' 06')", 6, parseFloat(" 06"));208 array[item++] = new TestCase( SECTION, "parseFloat(' 07')", 7, parseFloat(" 07"));209 array[item++] = new TestCase( SECTION, "parseFloat(' 010')", 10, parseFloat(" 010"));210 array[item++] = new TestCase( SECTION, "parseFloat(' 011')", 11, parseFloat(" 011"));211 // A StringNumericLIteral may have any number of leading 0 digits212 array[item++] = new TestCase( SECTION, "parseFloat(' 001')", 1, parseFloat(" 001"));213 array[item++] = new TestCase( SECTION, "parseFloat(' 0001')", 1, parseFloat(" 0001"));214 // A StringNumericLIteral may have any number of leading 0 digits215 array[item++] = new TestCase( SECTION, "parseFloat(001)", 1, parseFloat(001));216 array[item++] = new TestCase( SECTION, "parseFloat(0001)", 1, parseFloat(0001));217 // make sure it' s reflexive218 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.PI+' ')", Math.PI, parseFloat( ' ' +Math.PI+' '));219 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.LN2+' ')", Math.LN2, parseFloat( ' ' +Math.LN2+' '));220 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.LN10+' ')", Math.LN10, parseFloat( ' ' +Math.LN10+' '));221 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.LOG2E+' ')", Math.LOG2E, parseFloat( ' ' +Math.LOG2E+' '));222 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.LOG10E+' ')", Math.LOG10E, parseFloat( ' ' +Math.LOG10E+' '));223 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.SQRT2+' ')", Math.SQRT2, parseFloat( ' ' +Math.SQRT2+' '));224 array[item++] = new TestCase( SECTION, "parseFloat( ' ' +Math.SQRT1_2+' ')", Math.SQRT1_2, parseFloat( ' ' +Math.SQRT1_2+' '));225 return ( array );226}227function test( array ) {228 for ( tc=0; tc < testcases.length; tc++ ) {229 testcases[tc].passed = writeTestCaseResult(230 testcases[tc].expect,231 testcases[tc].actual,232 testcases[tc].description +" = "+ testcases[tc].actual );233 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";234 }235 stopTest();236 return ( testcases );...

Full Screen

Full Screen

11.4.6.js

Source:11.4.6.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 11.4.6.js24 ECMA Section: 11.4.6 Unary + Operator25 Description: convert operand to Number type26 Author: christine@netscape.com27 Date: 7 july 199728*/29 var SECTION = "11.4.6";30 var VERSION = "ECMA_1";31 startTest();32 var testcases = getTestCases();33 var BUGNUMBER="77391";34 writeHeaderToLog( SECTION + " Unary + operator");35 test();36function test() {37 for ( tc=0; tc < testcases.length; tc++ ) {38 testcases[tc].passed = writeTestCaseResult(39 testcases[tc].expect,40 testcases[tc].actual,41 testcases[tc].description +" = "+42 testcases[tc].actual );43 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";44 }45 stopTest();46 return ( testcases );47}48function getTestCases() {49 var array = new Array();50 var item = 0;51 array[item++] = new TestCase( SECTION, "+('')", 0, +("") );52 array[item++] = new TestCase( SECTION, "+(' ')", 0, +(" ") );53 array[item++] = new TestCase( SECTION, "+(\\t)", 0, +("\t") );54 array[item++] = new TestCase( SECTION, "+(\\n)", 0, +("\n") );55 array[item++] = new TestCase( SECTION, "+(\\r)", 0, +("\r") );56 array[item++] = new TestCase( SECTION, "+(\\f)", 0, +("\f") );57 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x0009)", 0, +(String.fromCharCode(0x0009)) );58 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x0020)", 0, +(String.fromCharCode(0x0020)) );59 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x000C)", 0, +(String.fromCharCode(0x000C)) );60 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x000B)", 0, +(String.fromCharCode(0x000B)) );61 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x000D)", 0, +(String.fromCharCode(0x000D)) );62 array[item++] = new TestCase( SECTION, "+(String.fromCharCode(0x000A)", 0, +(String.fromCharCode(0x000A)) );63 // a StringNumericLiteral may be preceeded or followed by whitespace and/or64 // line terminators65 array[item++] = new TestCase( SECTION, "+( ' ' + 999 )", 999, +( ' '+999) );66 array[item++] = new TestCase( SECTION, "+( '\\n' + 999 )", 999, +( '\n' +999) );67 array[item++] = new TestCase( SECTION, "+( '\\r' + 999 )", 999, +( '\r' +999) );68 array[item++] = new TestCase( SECTION, "+( '\\t' + 999 )", 999, +( '\t' +999) );69 array[item++] = new TestCase( SECTION, "+( '\\f' + 999 )", 999, +( '\f' +999) );70 array[item++] = new TestCase( SECTION, "+( 999 + ' ' )", 999, +( 999+' ') );71 array[item++] = new TestCase( SECTION, "+( 999 + '\\n' )", 999, +( 999+'\n' ) );72 array[item++] = new TestCase( SECTION, "+( 999 + '\\r' )", 999, +( 999+'\r' ) );73 array[item++] = new TestCase( SECTION, "+( 999 + '\\t' )", 999, +( 999+'\t' ) );74 array[item++] = new TestCase( SECTION, "+( 999 + '\\f' )", 999, +( 999+'\f' ) );75 array[item++] = new TestCase( SECTION, "+( '\\n' + 999 + '\\n' )", 999, +( '\n' +999+'\n' ) );76 array[item++] = new TestCase( SECTION, "+( '\\r' + 999 + '\\r' )", 999, +( '\r' +999+'\r' ) );77 array[item++] = new TestCase( SECTION, "+( '\\t' + 999 + '\\t' )", 999, +( '\t' +999+'\t' ) );78 array[item++] = new TestCase( SECTION, "+( '\\f' + 999 + '\\f' )", 999, +( '\f' +999+'\f' ) );79 array[item++] = new TestCase( SECTION, "+( ' ' + '999' )", 999, +( ' '+'999') );80 array[item++] = new TestCase( SECTION, "+( '\\n' + '999' )", 999, +( '\n' +'999') );81 array[item++] = new TestCase( SECTION, "+( '\\r' + '999' )", 999, +( '\r' +'999') );82 array[item++] = new TestCase( SECTION, "+( '\\t' + '999' )", 999, +( '\t' +'999') );83 array[item++] = new TestCase( SECTION, "+( '\\f' + '999' )", 999, +( '\f' +'999') );84 array[item++] = new TestCase( SECTION, "+( '999' + ' ' )", 999, +( '999'+' ') );85 array[item++] = new TestCase( SECTION, "+( '999' + '\\n' )", 999, +( '999'+'\n' ) );86 array[item++] = new TestCase( SECTION, "+( '999' + '\\r' )", 999, +( '999'+'\r' ) );87 array[item++] = new TestCase( SECTION, "+( '999' + '\\t' )", 999, +( '999'+'\t' ) );88 array[item++] = new TestCase( SECTION, "+( '999' + '\\f' )", 999, +( '999'+'\f' ) );89 array[item++] = new TestCase( SECTION, "+( '\\n' + '999' + '\\n' )", 999, +( '\n' +'999'+'\n' ) );90 array[item++] = new TestCase( SECTION, "+( '\\r' + '999' + '\\r' )", 999, +( '\r' +'999'+'\r' ) );91 array[item++] = new TestCase( SECTION, "+( '\\t' + '999' + '\\t' )", 999, +( '\t' +'999'+'\t' ) );92 array[item++] = new TestCase( SECTION, "+( '\\f' + '999' + '\\f' )", 999, +( '\f' +'999'+'\f' ) );93 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0009) + '99' )", 99, +( String.fromCharCode(0x0009) + '99' ) );94 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0020) + '99' )", 99, +( String.fromCharCode(0x0020) + '99' ) );95 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000C) + '99' )", 99, +( String.fromCharCode(0x000C) + '99' ) );96 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000B) + '99' )", 99, +( String.fromCharCode(0x000B) + '99' ) );97 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000D) + '99' )", 99, +( String.fromCharCode(0x000D) + '99' ) );98 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000A) + '99' )", 99, +( String.fromCharCode(0x000A) + '99' ) );99 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0009)) );100 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0020) + '99' + String.fromCharCode(0x0020)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x0020)) );101 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000C) + '99' + String.fromCharCode(0x000C)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000C)) );102 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000D) + '99' + String.fromCharCode(0x000D)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000D)) );103 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000B) + '99' + String.fromCharCode(0x000B)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000B)) );104 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000A) + '99' + String.fromCharCode(0x000A)", 99, +( String.fromCharCode(0x0009) + '99' + String.fromCharCode(0x000A)) );105 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x0009)", 99, +( '99' + String.fromCharCode(0x0009)) );106 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x0020)", 99, +( '99' + String.fromCharCode(0x0020)) );107 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000C)", 99, +( '99' + String.fromCharCode(0x000C)) );108 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000D)", 99, +( '99' + String.fromCharCode(0x000D)) );109 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000B)", 99, +( '99' + String.fromCharCode(0x000B)) );110 array[item++] = new TestCase( SECTION, "+( '99' + String.fromCharCode(0x000A)", 99, +( '99' + String.fromCharCode(0x000A)) );111 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0009) + 99 )", 99, +( String.fromCharCode(0x0009) + 99 ) );112 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0020) + 99 )", 99, +( String.fromCharCode(0x0020) + 99 ) );113 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000C) + 99 )", 99, +( String.fromCharCode(0x000C) + 99 ) );114 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000B) + 99 )", 99, +( String.fromCharCode(0x000B) + 99 ) );115 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000D) + 99 )", 99, +( String.fromCharCode(0x000D) + 99 ) );116 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000A) + 99 )", 99, +( String.fromCharCode(0x000A) + 99 ) );117 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0009)) );118 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x0020) + 99 + String.fromCharCode(0x0020)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x0020)) );119 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000C) + 99 + String.fromCharCode(0x000C)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000C)) );120 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000D) + 99 + String.fromCharCode(0x000D)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000D)) );121 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000B) + 99 + String.fromCharCode(0x000B)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000B)) );122 array[item++] = new TestCase( SECTION, "+( String.fromCharCode(0x000A) + 99 + String.fromCharCode(0x000A)", 99, +( String.fromCharCode(0x0009) + 99 + String.fromCharCode(0x000A)) );123 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x0009)", 99, +( 99 + String.fromCharCode(0x0009)) );124 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x0020)", 99, +( 99 + String.fromCharCode(0x0020)) );125 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000C)", 99, +( 99 + String.fromCharCode(0x000C)) );126 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000D)", 99, +( 99 + String.fromCharCode(0x000D)) );127 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000B)", 99, +( 99 + String.fromCharCode(0x000B)) );128 array[item++] = new TestCase( SECTION, "+( 99 + String.fromCharCode(0x000A)", 99, +( 99 + String.fromCharCode(0x000A)) );129 // StrNumericLiteral:::StrDecimalLiteral:::Infinity130 array[item++] = new TestCase( SECTION, "+('Infinity')", Math.pow(10,10000), +("Infinity") );131 array[item++] = new TestCase( SECTION, "+('-Infinity')", -Math.pow(10,10000), +("-Infinity") );132 array[item++] = new TestCase( SECTION, "+('+Infinity')", Math.pow(10,10000), +("+Infinity") );133 // StrNumericLiteral::: StrDecimalLiteral ::: DecimalDigits . DecimalDigits opt ExponentPart opt134 array[item++] = new TestCase( SECTION, "+('0')", 0, +("0") );135 array[item++] = new TestCase( SECTION, "+('-0')", -0, +("-0") );136 array[item++] = new TestCase( SECTION, "+('+0')", 0, +("+0") );137 array[item++] = new TestCase( SECTION, "+('1')", 1, +("1") );138 array[item++] = new TestCase( SECTION, "+('-1')", -1, +("-1") );139 array[item++] = new TestCase( SECTION, "+('+1')", 1, +("+1") );140 array[item++] = new TestCase( SECTION, "+('2')", 2, +("2") );141 array[item++] = new TestCase( SECTION, "+('-2')", -2, +("-2") );142 array[item++] = new TestCase( SECTION, "+('+2')", 2, +("+2") );143 array[item++] = new TestCase( SECTION, "+('3')", 3, +("3") );144 array[item++] = new TestCase( SECTION, "+('-3')", -3, +("-3") );145 array[item++] = new TestCase( SECTION, "+('+3')", 3, +("+3") );146 array[item++] = new TestCase( SECTION, "+('4')", 4, +("4") );147 array[item++] = new TestCase( SECTION, "+('-4')", -4, +("-4") );148 array[item++] = new TestCase( SECTION, "+('+4')", 4, +("+4") );149 array[item++] = new TestCase( SECTION, "+('5')", 5, +("5") );150 array[item++] = new TestCase( SECTION, "+('-5')", -5, +("-5") );151 array[item++] = new TestCase( SECTION, "+('+5')", 5, +("+5") );152 array[item++] = new TestCase( SECTION, "+('6')", 6, +("6") );153 array[item++] = new TestCase( SECTION, "+('-6')", -6, +("-6") );154 array[item++] = new TestCase( SECTION, "+('+6')", 6, +("+6") );155 array[item++] = new TestCase( SECTION, "+('7')", 7, +("7") );156 array[item++] = new TestCase( SECTION, "+('-7')", -7, +("-7") );157 array[item++] = new TestCase( SECTION, "+('+7')", 7, +("+7") );158 array[item++] = new TestCase( SECTION, "+('8')", 8, +("8") );159 array[item++] = new TestCase( SECTION, "+('-8')", -8, +("-8") );160 array[item++] = new TestCase( SECTION, "+('+8')", 8, +("+8") );161 array[item++] = new TestCase( SECTION, "+('9')", 9, +("9") );162 array[item++] = new TestCase( SECTION, "+('-9')", -9, +("-9") );163 array[item++] = new TestCase( SECTION, "+('+9')", 9, +("+9") );164 array[item++] = new TestCase( SECTION, "+('3.14159')", 3.14159, +("3.14159") );165 array[item++] = new TestCase( SECTION, "+('-3.14159')", -3.14159, +("-3.14159") );166 array[item++] = new TestCase( SECTION, "+('+3.14159')", 3.14159, +("+3.14159") );167 array[item++] = new TestCase( SECTION, "+('3.')", 3, +("3.") );168 array[item++] = new TestCase( SECTION, "+('-3.')", -3, +("-3.") );169 array[item++] = new TestCase( SECTION, "+('+3.')", 3, +("+3.") );170 array[item++] = new TestCase( SECTION, "+('3.e1')", 30, +("3.e1") );171 array[item++] = new TestCase( SECTION, "+('-3.e1')", -30, +("-3.e1") );172 array[item++] = new TestCase( SECTION, "+('+3.e1')", 30, +("+3.e1") );173 array[item++] = new TestCase( SECTION, "+('3.e+1')", 30, +("3.e+1") );174 array[item++] = new TestCase( SECTION, "+('-3.e+1')", -30, +("-3.e+1") );175 array[item++] = new TestCase( SECTION, "+('+3.e+1')", 30, +("+3.e+1") );176 array[item++] = new TestCase( SECTION, "+('3.e-1')", .30, +("3.e-1") );177 array[item++] = new TestCase( SECTION, "+('-3.e-1')", -.30, +("-3.e-1") );178 array[item++] = new TestCase( SECTION, "+('+3.e-1')", .30, +("+3.e-1") );179 // StrDecimalLiteral::: .DecimalDigits ExponentPart opt180 array[item++] = new TestCase( SECTION, "+('.00001')", 0.00001, +(".00001") );181 array[item++] = new TestCase( SECTION, "+('+.00001')", 0.00001, +("+.00001") );182 array[item++] = new TestCase( SECTION, "+('-0.0001')", -0.00001, +("-.00001") );183 array[item++] = new TestCase( SECTION, "+('.01e2')", 1, +(".01e2") );184 array[item++] = new TestCase( SECTION, "+('+.01e2')", 1, +("+.01e2") );185 array[item++] = new TestCase( SECTION, "+('-.01e2')", -1, +("-.01e2") );186 array[item++] = new TestCase( SECTION, "+('.01e+2')", 1, +(".01e+2") );187 array[item++] = new TestCase( SECTION, "+('+.01e+2')", 1, +("+.01e+2") );188 array[item++] = new TestCase( SECTION, "+('-.01e+2')", -1, +("-.01e+2") );189 array[item++] = new TestCase( SECTION, "+('.01e-2')", 0.0001, +(".01e-2") );190 array[item++] = new TestCase( SECTION, "+('+.01e-2')", 0.0001, +("+.01e-2") );191 array[item++] = new TestCase( SECTION, "+('-.01e-2')", -0.0001, +("-.01e-2") );192 // StrDecimalLiteral::: DecimalDigits ExponentPart opt193 array[item++] = new TestCase( SECTION, "+('1234e5')", 123400000, +("1234e5") );194 array[item++] = new TestCase( SECTION, "+('+1234e5')", 123400000, +("+1234e5") );195 array[item++] = new TestCase( SECTION, "+('-1234e5')", -123400000, +("-1234e5") );196 array[item++] = new TestCase( SECTION, "+('1234e+5')", 123400000, +("1234e+5") );197 array[item++] = new TestCase( SECTION, "+('+1234e+5')", 123400000, +("+1234e+5") );198 array[item++] = new TestCase( SECTION, "+('-1234e+5')", -123400000, +("-1234e+5") );199 array[item++] = new TestCase( SECTION, "+('1234e-5')", 0.01234, +("1234e-5") );200 array[item++] = new TestCase( SECTION, "+('+1234e-5')", 0.01234, +("+1234e-5") );201 array[item++] = new TestCase( SECTION, "+('-1234e-5')", -0.01234, +("-1234e-5") );202 // StrNumericLiteral::: HexIntegerLiteral203 array[item++] = new TestCase( SECTION, "+('0x0')", 0, +("0x0"));204 array[item++] = new TestCase( SECTION, "+('0x1')", 1, +("0x1"));205 array[item++] = new TestCase( SECTION, "+('0x2')", 2, +("0x2"));206 array[item++] = new TestCase( SECTION, "+('0x3')", 3, +("0x3"));207 array[item++] = new TestCase( SECTION, "+('0x4')", 4, +("0x4"));208 array[item++] = new TestCase( SECTION, "+('0x5')", 5, +("0x5"));209 array[item++] = new TestCase( SECTION, "+('0x6')", 6, +("0x6"));210 array[item++] = new TestCase( SECTION, "+('0x7')", 7, +("0x7"));211 array[item++] = new TestCase( SECTION, "+('0x8')", 8, +("0x8"));212 array[item++] = new TestCase( SECTION, "+('0x9')", 9, +("0x9"));213 array[item++] = new TestCase( SECTION, "+('0xa')", 10, +("0xa"));214 array[item++] = new TestCase( SECTION, "+('0xb')", 11, +("0xb"));215 array[item++] = new TestCase( SECTION, "+('0xc')", 12, +("0xc"));216 array[item++] = new TestCase( SECTION, "+('0xd')", 13, +("0xd"));217 array[item++] = new TestCase( SECTION, "+('0xe')", 14, +("0xe"));218 array[item++] = new TestCase( SECTION, "+('0xf')", 15, +("0xf"));219 array[item++] = new TestCase( SECTION, "+('0xA')", 10, +("0xA"));220 array[item++] = new TestCase( SECTION, "+('0xB')", 11, +("0xB"));221 array[item++] = new TestCase( SECTION, "+('0xC')", 12, +("0xC"));222 array[item++] = new TestCase( SECTION, "+('0xD')", 13, +("0xD"));223 array[item++] = new TestCase( SECTION, "+('0xE')", 14, +("0xE"));224 array[item++] = new TestCase( SECTION, "+('0xF')", 15, +("0xF"));225 array[item++] = new TestCase( SECTION, "+('0X0')", 0, +("0X0"));226 array[item++] = new TestCase( SECTION, "+('0X1')", 1, +("0X1"));227 array[item++] = new TestCase( SECTION, "+('0X2')", 2, +("0X2"));228 array[item++] = new TestCase( SECTION, "+('0X3')", 3, +("0X3"));229 array[item++] = new TestCase( SECTION, "+('0X4')", 4, +("0X4"));230 array[item++] = new TestCase( SECTION, "+('0X5')", 5, +("0X5"));231 array[item++] = new TestCase( SECTION, "+('0X6')", 6, +("0X6"));232 array[item++] = new TestCase( SECTION, "+('0X7')", 7, +("0X7"));233 array[item++] = new TestCase( SECTION, "+('0X8')", 8, +("0X8"));234 array[item++] = new TestCase( SECTION, "+('0X9')", 9, +("0X9"));235 array[item++] = new TestCase( SECTION, "+('0Xa')", 10, +("0Xa"));236 array[item++] = new TestCase( SECTION, "+('0Xb')", 11, +("0Xb"));237 array[item++] = new TestCase( SECTION, "+('0Xc')", 12, +("0Xc"));238 array[item++] = new TestCase( SECTION, "+('0Xd')", 13, +("0Xd"));239 array[item++] = new TestCase( SECTION, "+('0Xe')", 14, +("0Xe"));240 array[item++] = new TestCase( SECTION, "+('0Xf')", 15, +("0Xf"));241 array[item++] = new TestCase( SECTION, "+('0XA')", 10, +("0XA"));242 array[item++] = new TestCase( SECTION, "+('0XB')", 11, +("0XB"));243 array[item++] = new TestCase( SECTION, "+('0XC')", 12, +("0XC"));244 array[item++] = new TestCase( SECTION, "+('0XD')", 13, +("0XD"));245 array[item++] = new TestCase( SECTION, "+('0XE')", 14, +("0XE"));246 array[item++] = new TestCase( SECTION, "+('0XF')", 15, +("0XF"));247 return array;...

Full Screen

Full Screen

7.7.4.js

Source:7.7.4.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 7.7.4.js24 ECMA Section: 7.7.4 String Literals25 Description: A string literal is zero or more characters enclosed in26 single or double quotes. Each character may be27 represented by an escape sequence.28 Author: christine@netscape.com29 Date: 16 september 199730*/31 var SECTION = "7.7.4";32 var VERSION = "ECMA_1";33 startTest();34 var TITLE = "String Literals";35 writeHeaderToLog( SECTION + " "+ TITLE);36 var testcases = getTestCases();37 test();38function getTestCases() {39 var array = new Array();40 var item = 0;41 // StringLiteral:: "" and ''42 array[item++] = new TestCase( SECTION, "\"\"", "", "" );43 array[item++] = new TestCase( SECTION, "\'\'", "", '' );44 // DoubleStringCharacters:: DoubleStringCharacter :: EscapeSequence :: CharacterEscapeSequence45 array[item++] = new TestCase( SECTION, "\\\"", String.fromCharCode(0x0022), "\"" );46 array[item++] = new TestCase( SECTION, "\\\'", String.fromCharCode(0x0027), "\'" );47 array[item++] = new TestCase( SECTION, "\\", String.fromCharCode(0x005C), "\\" );48 array[item++] = new TestCase( SECTION, "\\b", String.fromCharCode(0x0008), "\b" );49 array[item++] = new TestCase( SECTION, "\\f", String.fromCharCode(0x000C), "\f" );50 array[item++] = new TestCase( SECTION, "\\n", String.fromCharCode(0x000A), "\n" );51 array[item++] = new TestCase( SECTION, "\\r", String.fromCharCode(0x000D), "\r" );52 array[item++] = new TestCase( SECTION, "\\t", String.fromCharCode(0x0009), "\t" );53 array[item++] = new TestCase( SECTION, "\\v", String.fromCharCode(0x000B), "\v" );54 // DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::OctalEscapeSequence55 array[item++] = new TestCase( SECTION, "\\00", String.fromCharCode(0x0000), "\00" );56 array[item++] = new TestCase( SECTION, "\\01", String.fromCharCode(0x0001), "\01" );57 array[item++] = new TestCase( SECTION, "\\02", String.fromCharCode(0x0002), "\02" );58 array[item++] = new TestCase( SECTION, "\\03", String.fromCharCode(0x0003), "\03" );59 array[item++] = new TestCase( SECTION, "\\04", String.fromCharCode(0x0004), "\04" );60 array[item++] = new TestCase( SECTION, "\\05", String.fromCharCode(0x0005), "\05" );61 array[item++] = new TestCase( SECTION, "\\06", String.fromCharCode(0x0006), "\06" );62 array[item++] = new TestCase( SECTION, "\\07", String.fromCharCode(0x0007), "\07" );63 array[item++] = new TestCase( SECTION, "\\010", String.fromCharCode(0x0008), "\010" );64 array[item++] = new TestCase( SECTION, "\\011", String.fromCharCode(0x0009), "\011" );65 array[item++] = new TestCase( SECTION, "\\012", String.fromCharCode(0x000A), "\012" );66 array[item++] = new TestCase( SECTION, "\\013", String.fromCharCode(0x000B), "\013" );67 array[item++] = new TestCase( SECTION, "\\014", String.fromCharCode(0x000C), "\014" );68 array[item++] = new TestCase( SECTION, "\\015", String.fromCharCode(0x000D), "\015" );69 array[item++] = new TestCase( SECTION, "\\016", String.fromCharCode(0x000E), "\016" );70 array[item++] = new TestCase( SECTION, "\\017", String.fromCharCode(0x000F), "\017" );71 array[item++] = new TestCase( SECTION, "\\020", String.fromCharCode(0x0010), "\020" );72 array[item++] = new TestCase( SECTION, "\\042", String.fromCharCode(0x0022), "\042" );73 array[item++] = new TestCase( SECTION, "\\0", String.fromCharCode(0x0000), "\0" );74 array[item++] = new TestCase( SECTION, "\\1", String.fromCharCode(0x0001), "\1" );75 array[item++] = new TestCase( SECTION, "\\2", String.fromCharCode(0x0002), "\2" );76 array[item++] = new TestCase( SECTION, "\\3", String.fromCharCode(0x0003), "\3" );77 array[item++] = new TestCase( SECTION, "\\4", String.fromCharCode(0x0004), "\4" );78 array[item++] = new TestCase( SECTION, "\\5", String.fromCharCode(0x0005), "\5" );79 array[item++] = new TestCase( SECTION, "\\6", String.fromCharCode(0x0006), "\6" );80 array[item++] = new TestCase( SECTION, "\\7", String.fromCharCode(0x0007), "\7" );81 array[item++] = new TestCase( SECTION, "\\10", String.fromCharCode(0x0008), "\10" );82 array[item++] = new TestCase( SECTION, "\\11", String.fromCharCode(0x0009), "\11" );83 array[item++] = new TestCase( SECTION, "\\12", String.fromCharCode(0x000A), "\12" );84 array[item++] = new TestCase( SECTION, "\\13", String.fromCharCode(0x000B), "\13" );85 array[item++] = new TestCase( SECTION, "\\14", String.fromCharCode(0x000C), "\14" );86 array[item++] = new TestCase( SECTION, "\\15", String.fromCharCode(0x000D), "\15" );87 array[item++] = new TestCase( SECTION, "\\16", String.fromCharCode(0x000E), "\16" );88 array[item++] = new TestCase( SECTION, "\\17", String.fromCharCode(0x000F), "\17" );89 array[item++] = new TestCase( SECTION, "\\20", String.fromCharCode(0x0010), "\20" );90 array[item++] = new TestCase( SECTION, "\\42", String.fromCharCode(0x0022), "\42" );91 array[item++] = new TestCase( SECTION, "\\000", String.fromCharCode(0), "\000" );92 array[item++] = new TestCase( SECTION, "\\111", String.fromCharCode(73), "\111" );93 array[item++] = new TestCase( SECTION, "\\222", String.fromCharCode(146), "\222" );94 array[item++] = new TestCase( SECTION, "\\333", String.fromCharCode(219), "\333" );95// following line commented out as it causes a compile time error96// array[item++] = new TestCase( SECTION, "\\444", "444", "\444" );97 // DoubleStringCharacters:DoubleStringCharacter::EscapeSequence::HexEscapeSequence98/*99 array[item++] = new TestCase( SECTION, "\\x0", String.fromCharCode(0), "\x0" );100 array[item++] = new TestCase( SECTION, "\\x1", String.fromCharCode(1), "\x1" );101 array[item++] = new TestCase( SECTION, "\\x2", String.fromCharCode(2), "\x2" );102 array[item++] = new TestCase( SECTION, "\\x3", String.fromCharCode(3), "\x3" );103 array[item++] = new TestCase( SECTION, "\\x4", String.fromCharCode(4), "\x4" );104 array[item++] = new TestCase( SECTION, "\\x5", String.fromCharCode(5), "\x5" );105 array[item++] = new TestCase( SECTION, "\\x6", String.fromCharCode(6), "\x6" );106 array[item++] = new TestCase( SECTION, "\\x7", String.fromCharCode(7), "\x7" );107 array[item++] = new TestCase( SECTION, "\\x8", String.fromCharCode(8), "\x8" );108 array[item++] = new TestCase( SECTION, "\\x9", String.fromCharCode(9), "\x9" );109 array[item++] = new TestCase( SECTION, "\\xA", String.fromCharCode(10), "\xA" );110 array[item++] = new TestCase( SECTION, "\\xB", String.fromCharCode(11), "\xB" );111 array[item++] = new TestCase( SECTION, "\\xC", String.fromCharCode(12), "\xC" );112 array[item++] = new TestCase( SECTION, "\\xD", String.fromCharCode(13), "\xD" );113 array[item++] = new TestCase( SECTION, "\\xE", String.fromCharCode(14), "\xE" );114 array[item++] = new TestCase( SECTION, "\\xF", String.fromCharCode(15), "\xF" );115*/116 array[item++] = new TestCase( SECTION, "\\xF0", String.fromCharCode(240), "\xF0" );117 array[item++] = new TestCase( SECTION, "\\xE1", String.fromCharCode(225), "\xE1" );118 array[item++] = new TestCase( SECTION, "\\xD2", String.fromCharCode(210), "\xD2" );119 array[item++] = new TestCase( SECTION, "\\xC3", String.fromCharCode(195), "\xC3" );120 array[item++] = new TestCase( SECTION, "\\xB4", String.fromCharCode(180), "\xB4" );121 array[item++] = new TestCase( SECTION, "\\xA5", String.fromCharCode(165), "\xA5" );122 array[item++] = new TestCase( SECTION, "\\x96", String.fromCharCode(150), "\x96" );123 array[item++] = new TestCase( SECTION, "\\x87", String.fromCharCode(135), "\x87" );124 array[item++] = new TestCase( SECTION, "\\x78", String.fromCharCode(120), "\x78" );125 array[item++] = new TestCase( SECTION, "\\x69", String.fromCharCode(105), "\x69" );126 array[item++] = new TestCase( SECTION, "\\x5A", String.fromCharCode(90), "\x5A" );127 array[item++] = new TestCase( SECTION, "\\x4B", String.fromCharCode(75), "\x4B" );128 array[item++] = new TestCase( SECTION, "\\x3C", String.fromCharCode(60), "\x3C" );129 array[item++] = new TestCase( SECTION, "\\x2D", String.fromCharCode(45), "\x2D" );130 array[item++] = new TestCase( SECTION, "\\x1E", String.fromCharCode(30), "\x1E" );131 array[item++] = new TestCase( SECTION, "\\x0F", String.fromCharCode(15), "\x0F" );132 // string literals only take up to two hext digits. therefore, the third character in this string133 // should be interpreted as a StringCharacter and not part of the HextEscapeSequence134 array[item++] = new TestCase( SECTION, "\\xF0F", String.fromCharCode(240)+"F", "\xF0F" );135 array[item++] = new TestCase( SECTION, "\\xE1E", String.fromCharCode(225)+"E", "\xE1E" );136 array[item++] = new TestCase( SECTION, "\\xD2D", String.fromCharCode(210)+"D", "\xD2D" );137 array[item++] = new TestCase( SECTION, "\\xC3C", String.fromCharCode(195)+"C", "\xC3C" );138 array[item++] = new TestCase( SECTION, "\\xB4B", String.fromCharCode(180)+"B", "\xB4B" );139 array[item++] = new TestCase( SECTION, "\\xA5A", String.fromCharCode(165)+"A", "\xA5A" );140 array[item++] = new TestCase( SECTION, "\\x969", String.fromCharCode(150)+"9", "\x969" );141 array[item++] = new TestCase( SECTION, "\\x878", String.fromCharCode(135)+"8", "\x878" );142 array[item++] = new TestCase( SECTION, "\\x787", String.fromCharCode(120)+"7", "\x787" );143 array[item++] = new TestCase( SECTION, "\\x696", String.fromCharCode(105)+"6", "\x696" );144 array[item++] = new TestCase( SECTION, "\\x5A5", String.fromCharCode(90)+"5", "\x5A5" );145 array[item++] = new TestCase( SECTION, "\\x4B4", String.fromCharCode(75)+"4", "\x4B4" );146 array[item++] = new TestCase( SECTION, "\\x3C3", String.fromCharCode(60)+"3", "\x3C3" );147 array[item++] = new TestCase( SECTION, "\\x2D2", String.fromCharCode(45)+"2", "\x2D2" );148 array[item++] = new TestCase( SECTION, "\\x1E1", String.fromCharCode(30)+"1", "\x1E1" );149 array[item++] = new TestCase( SECTION, "\\x0F0", String.fromCharCode(15)+"0", "\x0F0" );150 // G is out of hex range151 array[item++] = new TestCase( SECTION, "\\xG", "xG", "\xG" );152 array[item++] = new TestCase( SECTION, "\\xCG", "xCG", "\xCG" );153 // DoubleStringCharacter::EscapeSequence::CharacterEscapeSequence::\ NonEscapeCharacter154 array[item++] = new TestCase( SECTION, "\\a", "a", "\a" );155 array[item++] = new TestCase( SECTION, "\\c", "c", "\c" );156 array[item++] = new TestCase( SECTION, "\\d", "d", "\d" );157 array[item++] = new TestCase( SECTION, "\\e", "e", "\e" );158 array[item++] = new TestCase( SECTION, "\\g", "g", "\g" );159 array[item++] = new TestCase( SECTION, "\\h", "h", "\h" );160 array[item++] = new TestCase( SECTION, "\\i", "i", "\i" );161 array[item++] = new TestCase( SECTION, "\\j", "j", "\j" );162 array[item++] = new TestCase( SECTION, "\\k", "k", "\k" );163 array[item++] = new TestCase( SECTION, "\\l", "l", "\l" );164 array[item++] = new TestCase( SECTION, "\\m", "m", "\m" );165 array[item++] = new TestCase( SECTION, "\\o", "o", "\o" );166 array[item++] = new TestCase( SECTION, "\\p", "p", "\p" );167 array[item++] = new TestCase( SECTION, "\\q", "q", "\q" );168 array[item++] = new TestCase( SECTION, "\\s", "s", "\s" );169 array[item++] = new TestCase( SECTION, "\\u", "u", "\u" );170 array[item++] = new TestCase( SECTION, "\\w", "w", "\w" );171 array[item++] = new TestCase( SECTION, "\\x", "x", "\x" );172 array[item++] = new TestCase( SECTION, "\\y", "y", "\y" );173 array[item++] = new TestCase( SECTION, "\\z", "z", "\z" );174 array[item++] = new TestCase( SECTION, "\\9", "9", "\9" );175 array[item++] = new TestCase( SECTION, "\\A", "A", "\A" );176 array[item++] = new TestCase( SECTION, "\\B", "B", "\B" );177 array[item++] = new TestCase( SECTION, "\\C", "C", "\C" );178 array[item++] = new TestCase( SECTION, "\\D", "D", "\D" );179 array[item++] = new TestCase( SECTION, "\\E", "E", "\E" );180 array[item++] = new TestCase( SECTION, "\\F", "F", "\F" );181 array[item++] = new TestCase( SECTION, "\\G", "G", "\G" );182 array[item++] = new TestCase( SECTION, "\\H", "H", "\H" );183 array[item++] = new TestCase( SECTION, "\\I", "I", "\I" );184 array[item++] = new TestCase( SECTION, "\\J", "J", "\J" );185 array[item++] = new TestCase( SECTION, "\\K", "K", "\K" );186 array[item++] = new TestCase( SECTION, "\\L", "L", "\L" );187 array[item++] = new TestCase( SECTION, "\\M", "M", "\M" );188 array[item++] = new TestCase( SECTION, "\\N", "N", "\N" );189 array[item++] = new TestCase( SECTION, "\\O", "O", "\O" );190 array[item++] = new TestCase( SECTION, "\\P", "P", "\P" );191 array[item++] = new TestCase( SECTION, "\\Q", "Q", "\Q" );192 array[item++] = new TestCase( SECTION, "\\R", "R", "\R" );193 array[item++] = new TestCase( SECTION, "\\S", "S", "\S" );194 array[item++] = new TestCase( SECTION, "\\T", "T", "\T" );195 array[item++] = new TestCase( SECTION, "\\U", "U", "\U" );196 array[item++] = new TestCase( SECTION, "\\V", "V", "\V" );197 array[item++] = new TestCase( SECTION, "\\W", "W", "\W" );198 array[item++] = new TestCase( SECTION, "\\X", "X", "\X" );199 array[item++] = new TestCase( SECTION, "\\Y", "Y", "\Y" );200 array[item++] = new TestCase( SECTION, "\\Z", "Z", "\Z" );201 // DoubleStringCharacter::EscapeSequence::UnicodeEscapeSequence202 array[item++] = new TestCase( SECTION, "\\u0020", " ", "\u0020" );203 array[item++] = new TestCase( SECTION, "\\u0021", "!", "\u0021" );204 array[item++] = new TestCase( SECTION, "\\u0022", "\"", "\u0022" );205 array[item++] = new TestCase( SECTION, "\\u0023", "#", "\u0023" );206 array[item++] = new TestCase( SECTION, "\\u0024", "$", "\u0024" );207 array[item++] = new TestCase( SECTION, "\\u0025", "%", "\u0025" );208 array[item++] = new TestCase( SECTION, "\\u0026", "&", "\u0026" );209 array[item++] = new TestCase( SECTION, "\\u0027", "'", "\u0027" );210 array[item++] = new TestCase( SECTION, "\\u0028", "(", "\u0028" );211 array[item++] = new TestCase( SECTION, "\\u0029", ")", "\u0029" );212 array[item++] = new TestCase( SECTION, "\\u002A", "*", "\u002A" );213 array[item++] = new TestCase( SECTION, "\\u002B", "+", "\u002B" );214 array[item++] = new TestCase( SECTION, "\\u002C", ",", "\u002C" );215 array[item++] = new TestCase( SECTION, "\\u002D", "-", "\u002D" );216 array[item++] = new TestCase( SECTION, "\\u002E", ".", "\u002E" );217 array[item++] = new TestCase( SECTION, "\\u002F", "/", "\u002F" );218 array[item++] = new TestCase( SECTION, "\\u0030", "0", "\u0030" );219 array[item++] = new TestCase( SECTION, "\\u0031", "1", "\u0031" );220 array[item++] = new TestCase( SECTION, "\\u0032", "2", "\u0032" );221 array[item++] = new TestCase( SECTION, "\\u0033", "3", "\u0033" );222 array[item++] = new TestCase( SECTION, "\\u0034", "4", "\u0034" );223 array[item++] = new TestCase( SECTION, "\\u0035", "5", "\u0035" );224 array[item++] = new TestCase( SECTION, "\\u0036", "6", "\u0036" );225 array[item++] = new TestCase( SECTION, "\\u0037", "7", "\u0037" );226 array[item++] = new TestCase( SECTION, "\\u0038", "8", "\u0038" );227 array[item++] = new TestCase( SECTION, "\\u0039", "9", "\u0039" );228 return ( array );229}230function test() {231 for ( tc=0; tc < testcases.length; tc++ ) {232 testcases[tc].actual = testcases[tc].actual;233 testcases[tc].passed = writeTestCaseResult(234 testcases[tc].expect,235 testcases[tc].actual,236 testcases[tc].description +" = "+ testcases[tc].actual );237 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";238 }239 stopTest();240 return ( testcases );...

Full Screen

Full Screen

7.7.3.js

Source:7.7.3.js Github

copy

Full Screen

1/* The contents of this file are subject to the Netscape Public2 * License Version 1.1 (the "License"); you may not use this file3 * except in compliance with the License. You may obtain a copy of4 * the License at http://www.mozilla.org/NPL/5 *6 * Software distributed under the License is distributed on an "AS7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or8 * implied. See the License for the specific language governing9 * rights and limitations under the License.10 *11 * The Original Code is Mozilla Communicator client code, released March12 * 31, 1998.13 *14 * The Initial Developer of the Original Code is Netscape Communications15 * Corporation. Portions created by Netscape are16 * Copyright (C) 1998 Netscape Communications Corporation. All17 * Rights Reserved.18 *19 * Contributor(s): 20 * 21 */22/**23 File Name: 7.7.3.js24 ECMA Section: 7.7.3 Numeric Literals25 Description: A numeric literal stands for a value of the Number type26 This value is determined in two steps: first a27 mathematical value (MV) is derived from the literal;28 second, this mathematical value is rounded, ideally29 using IEEE 754 round-to-nearest mode, to a reprentable30 value of of the number type.31 Author: christine@netscape.com32 Date: 16 september 199733*/34 var SECTION = "7.7.3";35 var VERSION = "ECMA_1";36 startTest();37 var TITLE = "Numeric Literals";38 writeHeaderToLog( SECTION + " "+ TITLE);39 var testcases = getTestCases();40 test();41function getTestCases() {42 var array = new Array();43 var item = 0;44 array[item++] = new TestCase( SECTION, "0", 0, 0 );45 array[item++] = new TestCase( SECTION, "1", 1, 1 );46 array[item++] = new TestCase( SECTION, "2", 2, 2 );47 array[item++] = new TestCase( SECTION, "3", 3, 3 );48 array[item++] = new TestCase( SECTION, "4", 4, 4 );49 array[item++] = new TestCase( SECTION, "5", 5, 5 );50 array[item++] = new TestCase( SECTION, "6", 6, 6 );51 array[item++] = new TestCase( SECTION, "7", 7, 7 );52 array[item++] = new TestCase( SECTION, "8", 8, 8 );53 array[item++] = new TestCase( SECTION, "9", 9, 9 );54 array[item++] = new TestCase( SECTION, "0.", 0, 0. );55 array[item++] = new TestCase( SECTION, "1.", 1, 1. );56 array[item++] = new TestCase( SECTION, "2.", 2, 2. );57 array[item++] = new TestCase( SECTION, "3.", 3, 3. );58 array[item++] = new TestCase( SECTION, "4.", 4, 4. );59 array[item++] = new TestCase( SECTION, "0.e0", 0, 0.e0 );60 array[item++] = new TestCase( SECTION, "1.e1", 10, 1.e1 );61 array[item++] = new TestCase( SECTION, "2.e2", 200, 2.e2 );62 array[item++] = new TestCase( SECTION, "3.e3", 3000, 3.e3 );63 array[item++] = new TestCase( SECTION, "4.e4", 40000, 4.e4 );64 array[item++] = new TestCase( SECTION, "0.1e0", .1, 0.1e0 );65 array[item++] = new TestCase( SECTION, "1.1e1", 11, 1.1e1 );66 array[item++] = new TestCase( SECTION, "2.2e2", 220, 2.2e2 );67 array[item++] = new TestCase( SECTION, "3.3e3", 3300, 3.3e3 );68 array[item++] = new TestCase( SECTION, "4.4e4", 44000, 4.4e4 );69 array[item++] = new TestCase( SECTION, ".1e0", .1, .1e0 );70 array[item++] = new TestCase( SECTION, ".1e1", 1, .1e1 );71 array[item++] = new TestCase( SECTION, ".2e2", 20, .2e2 );72 array[item++] = new TestCase( SECTION, ".3e3", 300, .3e3 );73 array[item++] = new TestCase( SECTION, ".4e4", 4000, .4e4 );74 array[item++] = new TestCase( SECTION, "0e0", 0, 0e0 );75 array[item++] = new TestCase( SECTION, "1e1", 10, 1e1 );76 array[item++] = new TestCase( SECTION, "2e2", 200, 2e2 );77 array[item++] = new TestCase( SECTION, "3e3", 3000, 3e3 );78 array[item++] = new TestCase( SECTION, "4e4", 40000, 4e4 );79 array[item++] = new TestCase( SECTION, "0e0", 0, 0e0 );80 array[item++] = new TestCase( SECTION, "1e1", 10, 1e1 );81 array[item++] = new TestCase( SECTION, "2e2", 200, 2e2 );82 array[item++] = new TestCase( SECTION, "3e3", 3000, 3e3 );83 array[item++] = new TestCase( SECTION, "4e4", 40000, 4e4 );84 array[item++] = new TestCase( SECTION, "0E0", 0, 0E0 );85 array[item++] = new TestCase( SECTION, "1E1", 10, 1E1 );86 array[item++] = new TestCase( SECTION, "2E2", 200, 2E2 );87 array[item++] = new TestCase( SECTION, "3E3", 3000, 3E3 );88 array[item++] = new TestCase( SECTION, "4E4", 40000, 4E4 );89 array[item++] = new TestCase( SECTION, "1.e-1", 0.1, 1.e-1 );90 array[item++] = new TestCase( SECTION, "2.e-2", 0.02, 2.e-2 );91 array[item++] = new TestCase( SECTION, "3.e-3", 0.003, 3.e-3 );92 array[item++] = new TestCase( SECTION, "4.e-4", 0.0004, 4.e-4 );93 array[item++] = new TestCase( SECTION, "0.1e-0", .1, 0.1e-0 );94 array[item++] = new TestCase( SECTION, "1.1e-1", 0.11, 1.1e-1 );95 array[item++] = new TestCase( SECTION, "2.2e-2", .022, 2.2e-2 );96 array[item++] = new TestCase( SECTION, "3.3e-3", .0033, 3.3e-3 );97 array[item++] = new TestCase( SECTION, "4.4e-4", .00044, 4.4e-4 );98 array[item++] = new TestCase( SECTION, ".1e-0", .1, .1e-0 );99 array[item++] = new TestCase( SECTION, ".1e-1", .01, .1e-1 );100 array[item++] = new TestCase( SECTION, ".2e-2", .002, .2e-2 );101 array[item++] = new TestCase( SECTION, ".3e-3", .0003, .3e-3 );102 array[item++] = new TestCase( SECTION, ".4e-4", .00004, .4e-4 );103 array[item++] = new TestCase( SECTION, "1.e+1", 10, 1.e+1 );104 array[item++] = new TestCase( SECTION, "2.e+2", 200, 2.e+2 );105 array[item++] = new TestCase( SECTION, "3.e+3", 3000, 3.e+3 );106 array[item++] = new TestCase( SECTION, "4.e+4", 40000, 4.e+4 );107 array[item++] = new TestCase( SECTION, "0.1e+0", .1, 0.1e+0 );108 array[item++] = new TestCase( SECTION, "1.1e+1", 11, 1.1e+1 );109 array[item++] = new TestCase( SECTION, "2.2e+2", 220, 2.2e+2 );110 array[item++] = new TestCase( SECTION, "3.3e+3", 3300, 3.3e+3 );111 array[item++] = new TestCase( SECTION, "4.4e+4", 44000, 4.4e+4 );112 array[item++] = new TestCase( SECTION, ".1e+0", .1, .1e+0 );113 array[item++] = new TestCase( SECTION, ".1e+1", 1, .1e+1 );114 array[item++] = new TestCase( SECTION, ".2e+2", 20, .2e+2 );115 array[item++] = new TestCase( SECTION, ".3e+3", 300, .3e+3 );116 array[item++] = new TestCase( SECTION, ".4e+4", 4000, .4e+4 );117 array[item++] = new TestCase( SECTION, "0x0", 0, 0x0 );118 array[item++] = new TestCase( SECTION, "0x1", 1, 0x1 );119 array[item++] = new TestCase( SECTION, "0x2", 2, 0x2 );120 array[item++] = new TestCase( SECTION, "0x3", 3, 0x3 );121 array[item++] = new TestCase( SECTION, "0x4", 4, 0x4 );122 array[item++] = new TestCase( SECTION, "0x5", 5, 0x5 );123 array[item++] = new TestCase( SECTION, "0x6", 6, 0x6 );124 array[item++] = new TestCase( SECTION, "0x7", 7, 0x7 );125 array[item++] = new TestCase( SECTION, "0x8", 8, 0x8 );126 array[item++] = new TestCase( SECTION, "0x9", 9, 0x9 );127 array[item++] = new TestCase( SECTION, "0xa", 10, 0xa );128 array[item++] = new TestCase( SECTION, "0xb", 11, 0xb );129 array[item++] = new TestCase( SECTION, "0xc", 12, 0xc );130 array[item++] = new TestCase( SECTION, "0xd", 13, 0xd );131 array[item++] = new TestCase( SECTION, "0xe", 14, 0xe );132 array[item++] = new TestCase( SECTION, "0xf", 15, 0xf );133 array[item++] = new TestCase( SECTION, "0X0", 0, 0X0 );134 array[item++] = new TestCase( SECTION, "0X1", 1, 0X1 );135 array[item++] = new TestCase( SECTION, "0X2", 2, 0X2 );136 array[item++] = new TestCase( SECTION, "0X3", 3, 0X3 );137 array[item++] = new TestCase( SECTION, "0X4", 4, 0X4 );138 array[item++] = new TestCase( SECTION, "0X5", 5, 0X5 );139 array[item++] = new TestCase( SECTION, "0X6", 6, 0X6 );140 array[item++] = new TestCase( SECTION, "0X7", 7, 0X7 );141 array[item++] = new TestCase( SECTION, "0X8", 8, 0X8 );142 array[item++] = new TestCase( SECTION, "0X9", 9, 0X9 );143 array[item++] = new TestCase( SECTION, "0Xa", 10, 0Xa );144 array[item++] = new TestCase( SECTION, "0Xb", 11, 0Xb );145 array[item++] = new TestCase( SECTION, "0Xc", 12, 0Xc );146 array[item++] = new TestCase( SECTION, "0Xd", 13, 0Xd );147 array[item++] = new TestCase( SECTION, "0Xe", 14, 0Xe );148 array[item++] = new TestCase( SECTION, "0Xf", 15, 0Xf );149 array[item++] = new TestCase( SECTION, "0x0", 0, 0x0 );150 array[item++] = new TestCase( SECTION, "0x1", 1, 0x1 );151 array[item++] = new TestCase( SECTION, "0x2", 2, 0x2 );152 array[item++] = new TestCase( SECTION, "0x3", 3, 0x3 );153 array[item++] = new TestCase( SECTION, "0x4", 4, 0x4 );154 array[item++] = new TestCase( SECTION, "0x5", 5, 0x5 );155 array[item++] = new TestCase( SECTION, "0x6", 6, 0x6 );156 array[item++] = new TestCase( SECTION, "0x7", 7, 0x7 );157 array[item++] = new TestCase( SECTION, "0x8", 8, 0x8 );158 array[item++] = new TestCase( SECTION, "0x9", 9, 0x9 );159 array[item++] = new TestCase( SECTION, "0xA", 10, 0xA );160 array[item++] = new TestCase( SECTION, "0xB", 11, 0xB );161 array[item++] = new TestCase( SECTION, "0xC", 12, 0xC );162 array[item++] = new TestCase( SECTION, "0xD", 13, 0xD );163 array[item++] = new TestCase( SECTION, "0xE", 14, 0xE );164 array[item++] = new TestCase( SECTION, "0xF", 15, 0xF );165 array[item++] = new TestCase( SECTION, "0X0", 0, 0X0 );166 array[item++] = new TestCase( SECTION, "0X1", 1, 0X1 );167 array[item++] = new TestCase( SECTION, "0X2", 2, 0X2 );168 array[item++] = new TestCase( SECTION, "0X3", 3, 0X3 );169 array[item++] = new TestCase( SECTION, "0X4", 4, 0X4 );170 array[item++] = new TestCase( SECTION, "0X5", 5, 0X5 );171 array[item++] = new TestCase( SECTION, "0X6", 6, 0X6 );172 array[item++] = new TestCase( SECTION, "0X7", 7, 0X7 );173 array[item++] = new TestCase( SECTION, "0X8", 8, 0X8 );174 array[item++] = new TestCase( SECTION, "0X9", 9, 0X9 );175 array[item++] = new TestCase( SECTION, "0XA", 10, 0XA );176 array[item++] = new TestCase( SECTION, "0XB", 11, 0XB );177 array[item++] = new TestCase( SECTION, "0XC", 12, 0XC );178 array[item++] = new TestCase( SECTION, "0XD", 13, 0XD );179 array[item++] = new TestCase( SECTION, "0XE", 14, 0XE );180 array[item++] = new TestCase( SECTION, "0XF", 15, 0XF );181 array[item++] = new TestCase( SECTION, "00", 0, 00 );182 array[item++] = new TestCase( SECTION, "01", 1, 01 );183 array[item++] = new TestCase( SECTION, "02", 2, 02 );184 array[item++] = new TestCase( SECTION, "03", 3, 03 );185 array[item++] = new TestCase( SECTION, "04", 4, 04 );186 array[item++] = new TestCase( SECTION, "05", 5, 05 );187 array[item++] = new TestCase( SECTION, "06", 6, 06 );188 array[item++] = new TestCase( SECTION, "07", 7, 07 );189 array[item++] = new TestCase( SECTION, "000", 0, 000 );190 array[item++] = new TestCase( SECTION, "011", 9, 011 );191 array[item++] = new TestCase( SECTION, "022", 18, 022 );192 array[item++] = new TestCase( SECTION, "033", 27, 033 );193 array[item++] = new TestCase( SECTION, "044", 36, 044 );194 array[item++] = new TestCase( SECTION, "055", 45, 055 );195 array[item++] = new TestCase( SECTION, "066", 54, 066 );196 array[item++] = new TestCase( SECTION, "077", 63, 077 );197 array[item++] = new TestCase( SECTION, "0.00000000001", 0.00000000001, 0.00000000001 );198 array[item++] = new TestCase( SECTION, "0.00000000001e-2", 0.0000000000001, 0.00000000001e-2 );199 array[item++] = new TestCase( SECTION,200 "123456789012345671.9999",201 "123456789012345660",202 123456789012345671.9999 +"");203 array[item++] = new TestCase( SECTION,204 "123456789012345672",205 "123456789012345660",206 123456789012345672 +"");207 array[item++] = new TestCase( SECTION,208 "123456789012345672.000000000000000000000000000",209 "123456789012345660",210 123456789012345672.000000000000000000000000000 +"");211 array[item++] = new TestCase( SECTION,212 "123456789012345672.01",213 "123456789012345680",214 123456789012345672.01 +"");215 array[item++] = new TestCase( SECTION,216 "123456789012345672.000000000000000000000000001+'' == 123456789012345680 || 123456789012345660",217 true,218 ( 123456789012345672.00000000000000000000000000 +"" == 1234567890 * 100000000 + 12345680 )219 ||220 ( 123456789012345672.00000000000000000000000000 +"" == 1234567890 * 100000000 + 12345660) );221 array[item++] = new TestCase( SECTION,222 "123456789012345673",223 "123456789012345680",224 123456789012345673 +"" );225 array[item++] = new TestCase( SECTION,226 "-123456789012345671.9999",227 "-123456789012345660",228 -123456789012345671.9999 +"" );229 array[item++] = new TestCase( SECTION,230 "-123456789012345672",231 "-123456789012345660",232 -123456789012345672+"");233 array[item++] = new TestCase( SECTION,234 "-123456789012345672.000000000000000000000000000",235 "-123456789012345660",236 -123456789012345672.000000000000000000000000000 +"");237 array[item++] = new TestCase( SECTION,238 "-123456789012345672.01",239 "-123456789012345680",240 -123456789012345672.01 +"" );241 array[item++] = new TestCase( SECTION,242 "-123456789012345672.000000000000000000000000001 == -123456789012345680 or -123456789012345660",243 true,244 (-123456789012345672.000000000000000000000000001 +"" == -1234567890 * 100000000 -12345680)245 ||246 (-123456789012345672.000000000000000000000000001 +"" == -1234567890 * 100000000 -12345660));247 array[item++] = new TestCase( SECTION,248 -123456789012345673,249 "-123456789012345680",250 -123456789012345673 +"");251 array[item++] = new TestCase( SECTION,252 "12345678901234567890",253 "12345678901234567000",254 12345678901234567890 +"" );255/*256 array[item++] = new TestCase( SECTION, "12345678901234567", "12345678901234567", 12345678901234567+"" );257 array[item++] = new TestCase( SECTION, "123456789012345678", "123456789012345678", 123456789012345678+"" );258 array[item++] = new TestCase( SECTION, "1234567890123456789", "1234567890123456789", 1234567890123456789+"" );259 array[item++] = new TestCase( SECTION, "12345678901234567890", "12345678901234567890", 12345678901234567890+"" );260 array[item++] = new TestCase( SECTION, "123456789012345678900", "123456789012345678900", 123456789012345678900+"" );261 array[item++] = new TestCase( SECTION, "1234567890123456789000", "1234567890123456789000", 1234567890123456789000+"" );262*/263 array[item++] = new TestCase( SECTION, "0x1", 1, 0x1 );264 array[item++] = new TestCase( SECTION, "0x10", 16, 0x10 );265 array[item++] = new TestCase( SECTION, "0x100", 256, 0x100 );266 array[item++] = new TestCase( SECTION, "0x1000", 4096, 0x1000 );267 array[item++] = new TestCase( SECTION, "0x10000", 65536, 0x10000 );268 array[item++] = new TestCase( SECTION, "0x100000", 1048576, 0x100000 );269 array[item++] = new TestCase( SECTION, "0x1000000", 16777216, 0x1000000 );270 array[item++] = new TestCase( SECTION, "0x10000000", 268435456, 0x10000000 );271/*272 array[item++] = new TestCase( SECTION, "0x100000000", 4294967296, 0x100000000 );273 array[item++] = new TestCase( SECTION, "0x1000000000", 68719476736, 0x1000000000 );274 array[item++] = new TestCase( SECTION, "0x10000000000", 1099511627776, 0x10000000000 );275*/276 return ( array );277}278function test() {279 for ( tc=0; tc < testcases.length; tc++ ) {280 testcases[tc].actual = testcases[tc].actual;281 testcases[tc].passed = writeTestCaseResult(282 testcases[tc].expect,283 testcases[tc].actual,284 testcases[tc].description +" = "+ testcases[tc].actual );285 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";286 }287 stopTest();288 return ( testcases );...

Full Screen

Full Screen

test-test-case.js

Source:test-test-case.js Github

copy

Full Screen

1var common = require('../common');2var sinon = require('sinon');3var assert = require('assert');4var Sandbox = common.sandbox('test_case');5var TestCase = Sandbox.exports;6var testCase;7function test(fn) {8 testCase = new TestCase();9 fn();10}11test(function createFactory() {12 var testCase = TestCase.create(10);13 assert.strictEqual(testCase.testTimeout, 10);14});15test(function sugarAddTestFunction() {16 var sugarAddTest = testCase.sugarAddTest();17 Object18 .keys(TestCase.prototype)19 .concat(Object.keys(testCase))20 .forEach(function(property) {21 if (typeof testCase[property] !== 'function') {22 assert.strictEqual(sugarAddTest[property], testCase[property]);23 return;24 }25 var returns = 'the answer';26 var args = [1, 2, 3];27 testCase[property] = sinon.stub().returns(returns);28 var r = sugarAddTest[property].apply(null, args);29 assert.strictEqual(returns, r);30 assert.ok(testCase[property].calledOn(testCase));31 assert.ok(testCase[property].calledWith(1, 2, 3));32 assert.ok(testCase[property].callCount, 1);33 });34 var returns = 'another answer';35 var args = [1, 2];36 testCase.addTest = sinon.stub().returns(returns);37 var r = sugarAddTest.apply(null, args);38 assert.strictEqual(r, returns);39 assert.ok(testCase.addTest.calledOn(testCase));40 assert.ok(testCase.addTest.calledWith(1, 2));41 assert.ok(testCase.addTest.callCount, 1);42});43test(function addTestWithNameAndFn() {44 var testName = 'my test';45 var testFn = function() {};46 testCase.addTest(testName, testFn);47 assert.equal(testCase.tests.length, 1);48 assert.equal(testCase.tests[0].name, testName);49 assert.equal(testCase.tests[0].testFn, testFn);50 assert.equal(testCase.tests[0].timeout, null);51});52test(function addTestWithOptions() {53 var testName = 'my test';54 var testFn = function() {};55 var options = {foo: 'bar'};56 testCase.addTest(testName, options, testFn);57 assert.equal(testCase.tests[0].name, testName);58 assert.equal(testCase.tests[0].testFn, testFn);59 assert.equal(testCase.tests[0].foo, options.foo);60});61test(function addTestWithTestTimeout() {62 testCase.testTimeout = 20;63 var testName = 'my test';64 var testFn = function() {};65 testCase.addTest(testName, testFn);66 assert.equal(testCase.tests[0].timeout, 20);67});68test(function addTestWithTestTimeoutAndOptions() {69 testCase.testTimeout = 20;70 var testName = 'my test';71 var testFn = function() {};72 var testOptions = {};73 testCase.addTest(testName, testOptions, testFn);74 assert.equal(testCase.tests[0].timeout, 20);75});76test(function addTestWithTestTimeoutAndTimeoutOption() {77 testCase.testTimeout = 20;78 var testName = 'my test';79 var testFn = function() {};80 var testOptions = {timeout: 50};81 testCase.addTest(testName, testOptions, testFn);82 assert.equal(testCase.tests[0].timeout, 50);83});84test(function addTestCaseWithBeforeAndAfterFn() {85 var before = function() {};86 var after = function() {};87 testCase.before(before);88 testCase.after(after);89 var testName = 'my test';90 var testFn = function() {};91 testCase.addTest(testName, testFn);92 assert.strictEqual(testCase.tests[0].beforeFn, before);93 assert.strictEqual(testCase.tests[0].afterFn, after);94});95test(function runNoTestCases() {96 var runCb = sinon.spy();97 testCase.run(runCb);98 assert.ok(runCb.called);99 assert.ok(runCb.calledWith(null));100 assert.ok(testCase._started);101 assert.ok(testCase._ended);102});103test(function runOneSuccessTest() {104 var testInstance = {};105 testInstance.run = sinon.stub().yields(null);106 sinon.stub(testCase, 'selectedCount');107 testCase.tests.push(testInstance);108 var runCb = sinon.spy();109 testCase.run(runCb);110 assert.ok(runCb.calledWith(null));111});112test(function runOneErrorTest() {113 var err = new Error('something went wrong');114 var testInstance = {};115 testInstance.run = sinon.stub().yields(err);116 testCase.tests.push(testInstance);117 sinon.stub(testCase, 'selectedCount');118 var runCb = sinon.spy();119 testCase.run(runCb);120 assert.ok(runCb.calledWith([err]));121});122test(function runOneSuccessAndOneErrorTest() {123 var err = new Error('something went wrong');124 sinon.stub(testCase, 'selectedCount');125 var errorTest = {my: 'error test'};126 errorTest.run = sinon.stub().yields(err);127 testCase.tests.push(errorTest);128 var successTest = {my: 'success test'};129 successTest.run = sinon.stub().yields(null);130 testCase.tests.push(successTest);131 var emitTestEnd = sinon.spy();132 testCase.on('test.end', emitTestEnd);133 var runCb = sinon.spy();134 testCase.run(runCb);135 assert.ok(runCb.calledWith([err]));136 assert.ok(emitTestEnd.calledWith(errorTest));137 assert.ok(emitTestEnd.calledWith(successTest));138});139test(function runWithSelected() {140 testCase.tests = [141 {selected: sinon.stub().returns(false), run: sinon.stub().yields(null)},142 {selected: sinon.stub().returns(true), run: sinon.stub().yields(null)},143 ];144 var runCb = sinon.spy();145 testCase.run(runCb);146 assert.ok(runCb.calledWith(null));147 assert.equal(testCase.tests[0].run.called, false);148 assert.equal(testCase.tests[1].run.called, true);149 var stats = testCase.stats();150 assert.equal(stats.index, 2);151 assert.equal(stats.pass, 1);152 assert.equal(stats.skip, 1);153 assert.equal(stats.fail, 0);154 assert.equal(stats.total, 2);155});156test(function selectedCount() {157 testCase.tests = [158 {selected: sinon.stub().returns(false)},159 {selected: sinon.stub().returns(false)},160 ];161 assert.equal(testCase.selectedCount(), 0);162 testCase.tests.push({selected: sinon.stub().returns(true)});163 assert.equal(testCase.selectedCount(), 1);164});165test(function duration() {166 testCase._started = 20;167 testCase._ended = 30;168 assert.equal(testCase.duration(), 10);169});170test(function durationBeforeEnded() {171 testCase._started = +new Date;172 assert.ok(testCase.duration() >= 0);173 assert.ok(testCase.duration() < 10);174});175test(function statsNumbers() {176 testCase.tests = {length: 5};177 testCase.errors = {length: 3};178 testCase.index = 4;179 var stats = testCase.stats();180 assert.strictEqual(stats.pass, 1);181 assert.strictEqual(stats.fail, 3);182 assert.strictEqual(stats.index, testCase.index);183 assert.strictEqual(stats.total, 5);184});185test(function endWithoutCb() {186 testCase.end();187});188test(function endEmitsEvent() {189 var endCb = sinon.spy();190 testCase.on('end', endCb);191 testCase.end();192 assert.ok(endCb.called);...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful