1/* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22/** 23 File Name: 15.1.2.2-1.js 24 ECMA Section: 15.1.2.2 Function properties of the global object 25 parseInt( string, radix ) 26 27 Description: parseInt test cases written by waldemar, and documented in 28 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123874. 29 30 Author: christine@netscape.com 31 Date: 28 october 1997 32 33*/ 34var SECTION = "15.1.2.2-2"; 35var VERSION = "ECMA_1"; 36 startTest(); 37var TITLE = "parseInt(string, radix)"; 38var BUGNUMBER="123874"; 39 40writeHeaderToLog( SECTION + " "+ TITLE); 41 42var testcases = new Array(); 43 44testcases[tc++] = new TestCase( SECTION, 45 'parseInt("000000100000000100100011010001010110011110001001101010111100",2)', 46 9027215253084860, 47 parseInt("000000100000000100100011010001010110011110001001101010111100",2) ); 48 49testcases[tc++] = new TestCase( SECTION, 50 'parseInt("000000100000000100100011010001010110011110001001101010111101",2)', 51 9027215253084860, 52 parseInt("000000100000000100100011010001010110011110001001101010111101",2)); 53 54testcases[tc++] = new TestCase( SECTION, 55 'parseInt("000000100000000100100011010001010110011110001001101010111111",2)', 56 9027215253084864, 57 parseInt("000000100000000100100011010001010110011110001001101010111111",2) ); 58 59testcases[tc++] = new TestCase( SECTION, 60 'parseInt("0000001000000001001000110100010101100111100010011010101111010",2)', 61 18054430506169720, 62 parseInt("0000001000000001001000110100010101100111100010011010101111010",2) ); 63 64testcases[tc++] = new TestCase( SECTION, 65 'parseInt("0000001000000001001000110100010101100111100010011010101111011",2)', 66 18054430506169724, 67 parseInt("0000001000000001001000110100010101100111100010011010101111011",2)); 68 69testcases[tc++] = new TestCase( SECTION, 70 'parseInt("0000001000000001001000110100010101100111100010011010101111100",2)', 71 18054430506169724, 72 parseInt("0000001000000001001000110100010101100111100010011010101111100",2) ); 73 74testcases[tc++] = new TestCase( SECTION, 75 'parseInt("0000001000000001001000110100010101100111100010011010101111110",2)', 76 18054430506169728, 77 parseInt("0000001000000001001000110100010101100111100010011010101111110",2) ); 78 79testcases[tc++] = new TestCase( SECTION, 80 'parseInt("yz",35)', 81 34, 82 parseInt("yz",35) ); 83 84testcases[tc++] = new TestCase( SECTION, 85 'parseInt("yz",36)', 86 1259, 87 parseInt("yz",36) ); 88 89testcases[tc++] = new TestCase( SECTION, 90 'parseInt("yz",37)', 91 NaN, 92 parseInt("yz",37) ); 93 94testcases[tc++] = new TestCase( SECTION, 95 'parseInt("+77")', 96 77, 97 parseInt("+77") ); 98 99testcases[tc++] = new TestCase( SECTION, 100 'parseInt("-77",9)', 101 -70, 102 parseInt("-77",9) ); 103 104testcases[tc++] = new TestCase( SECTION, 105 'parseInt("\u20001234\u2000")', 106 1234, 107 parseInt("\u20001234\u2000") ); 108 109testcases[tc++] = new TestCase( SECTION, 110 'parseInt("123456789012345678")', 111 123456789012345680, 112 parseInt("123456789012345678") ); 113 114testcases[tc++] = new TestCase( SECTION, 115 'parseInt("9",8)', 116 NaN, 117 parseInt("9",8) ); 118 119testcases[tc++] = new TestCase( SECTION, 120 'parseInt("1e2")', 121 1, 122 parseInt("1e2") ); 123 124testcases[tc++] = new TestCase( SECTION, 125 'parseInt("1.9999999999999999999")', 126 1, 127 parseInt("1.9999999999999999999") ); 128 129testcases[tc++] = new TestCase( SECTION, 130 'parseInt("0x10")', 131 16, 132 parseInt("0x10") ); 133 134testcases[tc++] = new TestCase( SECTION, 135 'parseInt("0x10",10)', 136 0, 137 parseInt("0x10",10)); 138 139testcases[tc++] = new TestCase( SECTION, 140 'parseInt("0022")', 141 18, 142 parseInt("0022")); 143 144testcases[tc++] = new TestCase( SECTION, 145 'parseInt("0022",10)', 146 22, 147 parseInt("0022",10) ); 148 149testcases[tc++] = new TestCase( SECTION, 150 'parseInt("0x1000000000000080")', 151 1152921504606847000, 152 parseInt("0x1000000000000080") ); 153 154testcases[tc++] = new TestCase( SECTION, 155 'parseInt("0x1000000000000081")', 156 1152921504606847200, 157 parseInt("0x1000000000000081") ); 158 159s = 160"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 161 162s += "0000000000000000000000000000000000000"; 163 164testcases[tc++] = new TestCase( SECTION, 165 "s = " + s +"; -s", 166 -1.7976931348623157e+308, 167 -s ); 168 169s = 170"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; 171s += "0000000000000000000000000000000000001"; 172 173testcases[tc++] = new TestCase( SECTION, 174 "s = " + s +"; -s", 175 -1.7976931348623157e+308, 176 -s ); 177 178 179s = "0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; 180 181s += "0000000000000000000000000000000000000" 182 183 184testcases[tc++] = new TestCase( SECTION, 185 "s = " + s + "; -s", 186 -Infinity, 187 -s ); 188 189s = "0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; 190s += "0000000000000000000000000000000000001"; 191 192testcases[tc++] = new TestCase( SECTION, 193 "s = " + s + "; -s", 194 -1.7976931348623157e+308, 195 -s ); 196 197s += "0" 198 199testcases[tc++] = new TestCase( SECTION, 200 "s = " + s + "; -s", 201 -Infinity, 202 -s ); 203 204testcases[tc++] = new TestCase( SECTION, 205 'parseInt(s)', 206 Infinity, 207 parseInt(s) ); 208 209testcases[tc++] = new TestCase( SECTION, 210 'parseInt(s,32)', 211 0, 212 parseInt(s,32) ); 213 214testcases[tc++] = new TestCase( SECTION, 215 'parseInt(s,36)', 216 Infinity, 217 parseInt(s,36)); 218 219test(); 220 221function test( array ) { 222 for ( tc=0 ; tc < testcases.length; tc++ ) { 223 testcases[tc].passed = writeTestCaseResult( 224 testcases[tc].expect, 225 testcases[tc].actual, 226 testcases[tc].description +" = "+ testcases[tc].actual ); 227 228 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 229 } 230 stopTest(); 231 return ( testcases ); 232} 233