1
/* The contents of this file are subject to the Netscape Public
2
* License Version 1.1 (the "License"); you may not use this file
3
* except in compliance with the License. You may obtain a copy of
4
* the License at http://www.mozilla.org/NPL/
6
* Software distributed under the License is distributed on an "AS
7
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8
* implied. See the License for the specific language governing
9
* rights and limitations under the License.
11
* The Original Code is Mozilla Communicator client code, released March
14
* The Initial Developer of the Original Code is Netscape Communications
15
* Corporation. Portions created by Netscape are
16
* Copyright (C) 1998 Netscape Communications Corporation. All
24
ECMA Section: 9.3 Type Conversion: ToNumber
25
Description: rules for converting an argument to a number.
26
see 9.3.1 for cases for converting strings to numbers.
30
Boolean 1 if true; +0 if false
31
Number the argument ( no conversion )
36
Test cases provided by waldemar.
39
Author: christine@netscape.com
44
var SECTION = "9.3.1-3";
45
var VERSION = "ECMA_1";
47
var BUGNUMBER="129087";
49
var TITLE = "Number To String, String To Number";
51
writeHeaderToLog( SECTION + " "+ TITLE);
53
var testcases = new Array();
56
// test case from http://scopus.mcom.com/bugsplat/show_bug.cgi?id=312954
59
testcases[tc++] = new TestCase(
61
"var z = 0; print(1/-z)",
69
// test cases from bug http://scopus.mcom.com/bugsplat/show_bug.cgi?id=122882
73
testcases[tc++] = new TestCase( SECTION,
78
testcases[tc++] = new TestCase( SECTION,
83
testcases[tc++] = new TestCase( SECTION,
84
'- "-0x123456789abcde8"',
86
- "-0x123456789abcde8" );
88
// Convert some large numbers to string
91
testcases[tc++] = new TestCase( SECTION,
96
testcases[tc++] = new TestCase( SECTION,
101
testcases[tc++] = new TestCase( SECTION,
106
testcases[tc++] = new TestCase( SECTION,
111
testcases[tc++] = new TestCase( SECTION,
116
testcases[tc++] = new TestCase( SECTION,
121
testcases[tc++] = new TestCase( SECTION,
126
// convert some strings to large numbers
128
testcases[tc++] = new TestCase( SECTION,
133
testcases[tc++] = new TestCase( SECTION,
138
testcases[tc++] = new TestCase( SECTION,
143
testcases[tc++] = new TestCase( SECTION,
144
"parseFloat(\"1e2000\")",
146
parseFloat("1e2000") );
148
testcases[tc++] = new TestCase( SECTION,
149
"parseFloat(\"1e-2000\")",
151
parseFloat("1e-2000") );
153
testcases[tc++] = new TestCase( SECTION,
154
"1.7976931348623157E+308",
155
1.7976931348623157e+308,
156
1.7976931348623157E+308 );
158
testcases[tc++] = new TestCase( SECTION,
159
"1.7976931348623158e+308",
160
1.7976931348623157e+308,
161
1.7976931348623158e+308 );
163
testcases[tc++] = new TestCase( SECTION,
164
"1.7976931348623159e+308",
166
1.7976931348623159e+308 );
169
"17976931348623158079372897140530341507993413271003782693617377898044496829276475094664901797758720709633028641669288791094655554785194040263065748867150582068";
171
testcases[tc++] = new TestCase( SECTION,
172
"s = " + s +"; s +="+
173
"\"190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779\""+
176
"17976931348623158079372897140530341507993413271003782693617377898044496829276475094664901797758720709633028641669288791094655554785194040263065748867150582068190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779",
178
"190890200070838367627385484581771153176447573027006985557136695962284291481986083493647529271907416844436551070434271155969950809304288017790417449779"
183
testcases[tc++] = new TestCase( SECTION,
185
"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791",
188
/***** This answer is preferred but -Infinity is also acceptable here *****/
190
testcases[tc++] = new TestCase( SECTION,
191
"-s1 == Infinity || s1 == 1.7976931348623157e+308",
193
-s1 == Infinity || s1 == 1.7976931348623157e+308 );
197
testcases[tc++] = new TestCase( SECTION,
199
"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792",
202
// ***** This answer is preferred but -1.7976931348623157e+308 is also acceptable here *****
203
testcases[tc++] = new TestCase( SECTION,
204
"-s2 == -Infinity || -s2 == -1.7976931348623157e+308 ",
206
-s2 == -Infinity || -s2 == -1.7976931348623157e+308 );
210
testcases[tc++] = new TestCase( SECTION,
212
"179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497793",
215
//***** This answer is preferred but -1.7976931348623157e+308 is also acceptable here *****
217
testcases[tc++] = new TestCase( SECTION,
218
"-s3 == -Infinity || -s3 == -1.7976931348623157e+308",
220
-s3 == -Infinity || -s3 == -1.7976931348623157e+308 );
223
//***** This answer is preferred but Infinity is also acceptable here *****
225
testcases[tc++] = new TestCase( SECTION,
226
"parseInt(s1,10) == 1.7976931348623157e+308 || parseInt(s1,10) == Infinity",
228
parseInt(s1,10) == 1.7976931348623157e+308 || parseInt(s1,10) == Infinity );
230
//***** This answer is preferred but 1.7976931348623157e+308 is also acceptable here *****
231
testcases[tc++] = new TestCase( SECTION,
232
"parseInt(s2,10) == Infinity || parseInt(s2,10) == 1.7976931348623157e+308",
234
parseInt(s2,10) == Infinity || parseInt(s2,10) == 1.7976931348623157e+308 );
236
//***** This answer is preferred but Infinity is also acceptable here *****
238
testcases[tc++] = new TestCase( SECTION,
239
"parseInt(s1) == 1.7976931348623157e+308 || parseInt(s1) == Infinity",
241
parseInt(s1) == 1.7976931348623157e+308 || parseInt(s1) == Infinity);
243
//***** This answer is preferred but 1.7976931348623157e+308 is also acceptable here *****
244
testcases[tc++] = new TestCase( SECTION,
245
"parseInt(s2) == Infinity || parseInt(s2) == 1.7976931348623157e+308",
247
parseInt(s2) == Infinity || parseInt(s2) == 1.7976931348623157e+308 );
249
testcases[tc++] = new TestCase( SECTION,
254
testcases[tc++] = new TestCase( SECTION,
259
testcases[tc++] = new TestCase( SECTION,
264
testcases[tc++] = new TestCase( SECTION,
269
testcases[tc++] = new TestCase( SECTION,
270
"077777777777777777",
272
077777777777777777 );
274
testcases[tc++] = new TestCase( SECTION,
275
"077777777777777776",
277
077777777777777776 );
279
testcases[tc++] = new TestCase( SECTION,
284
testcases[tc++] = new TestCase( SECTION,
289
testcases[tc++] = new TestCase( SECTION,
294
testcases[tc++] = new TestCase( SECTION,
299
testcases[tc++] = new TestCase( SECTION,
304
testcases[tc++] = new TestCase( SECTION,
309
/***** These test the round-to-nearest-or-even-if-equally-close rule *****/
311
testcases[tc++] = new TestCase( SECTION,
312
"0x1000000000000080",
314
0x1000000000000080 );
316
testcases[tc++] = new TestCase( SECTION,
317
"0x1000000000000081",
319
0x1000000000000081 );
321
testcases[tc++] = new TestCase( SECTION,
322
"0x1000000000000100",
324
0x1000000000000100 );
325
testcases[tc++] = new TestCase( SECTION,
326
"0x100000000000017f",
328
0x100000000000017f );
330
testcases[tc++] = new TestCase( SECTION,
331
"0x1000000000000180",
333
0x1000000000000180 );
335
testcases[tc++] = new TestCase( SECTION,
336
"0x1000000000000181",
338
0x1000000000000181 );
340
testcases[tc++] = new TestCase( SECTION,
341
"0x10000000000001f0",
343
0x10000000000001f0 );
345
testcases[tc++] = new TestCase( SECTION,
346
"0x1000000000000200",
348
0x1000000000000200 );
350
testcases[tc++] = new TestCase( SECTION,
351
"0x100000000000027f",
353
0x100000000000027f );
355
testcases[tc++] = new TestCase( SECTION,
356
"0x1000000000000280",
358
0x1000000000000280 );
360
testcases[tc++] = new TestCase( SECTION,
361
"0x1000000000000281",
363
0x1000000000000281 );
365
testcases[tc++] = new TestCase( SECTION,
366
"0x10000000000002ff",
368
0x10000000000002ff );
370
testcases[tc++] = new TestCase( SECTION,
371
"0x1000000000000300",
373
0x1000000000000300 );
375
testcases[tc++] = new TestCase( SECTION,
376
"0x10000000000000000",
377
18446744073709552000,
378
0x10000000000000000 );
380
testcases[tc++] = new TestCase( SECTION,
381
"parseInt(\"000000100000000100100011010001010110011110001001101010111100\",2)",
383
parseInt("000000100000000100100011010001010110011110001001101010111100",2) );
385
testcases[tc++] = new TestCase( SECTION,
386
"parseInt(\"000000100000000100100011010001010110011110001001101010111101\",2)",
388
parseInt("000000100000000100100011010001010110011110001001101010111101",2) );
390
testcases[tc++] = new TestCase( SECTION,
391
"parseInt(\"000000100000000100100011010001010110011110001001101010111111\",2)",
393
parseInt("000000100000000100100011010001010110011110001001101010111111",2) );
395
testcases[tc++] = new TestCase( SECTION,
396
"parseInt(\"0000001000000001001000110100010101100111100010011010101111010\",2)",
398
parseInt("0000001000000001001000110100010101100111100010011010101111010",2));
400
testcases[tc++] = new TestCase( SECTION,
401
"parseInt(\"0000001000000001001000110100010101100111100010011010101111011\",2)",
403
parseInt("0000001000000001001000110100010101100111100010011010101111011",2) );
405
testcases[tc++] = new TestCase( SECTION,
406
"parseInt(\"0000001000000001001000110100010101100111100010011010101111100\",2)",
408
parseInt("0000001000000001001000110100010101100111100010011010101111100",2));
410
testcases[tc++] = new TestCase( SECTION,
411
"parseInt(\"0000001000000001001000110100010101100111100010011010101111110\",2)",
413
parseInt("0000001000000001001000110100010101100111100010011010101111110",2));
415
testcases[tc++] = new TestCase( SECTION,
416
"parseInt(\"yz\",35)",
420
testcases[tc++] = new TestCase( SECTION,
421
"parseInt(\"yz\",36)",
425
testcases[tc++] = new TestCase( SECTION,
426
"parseInt(\"yz\",37)",
430
testcases[tc++] = new TestCase( SECTION,
435
testcases[tc++] = new TestCase( SECTION,
436
"parseInt(\"-77\",9)",
440
testcases[tc++] = new TestCase( SECTION,
441
"parseInt(\"\\u20001234\\u2000\")",
443
parseInt("\u20001234\u2000") );
445
testcases[tc++] = new TestCase( SECTION,
446
"parseInt(\"123456789012345678\")",
448
parseInt("123456789012345678") );
450
testcases[tc++] = new TestCase( SECTION,
455
testcases[tc++] = new TestCase( SECTION,
460
testcases[tc++] = new TestCase( SECTION,
461
"parseInt(\"1.9999999999999999999\")",
463
parseInt("1.9999999999999999999") );
465
testcases[tc++] = new TestCase( SECTION,
466
"parseInt(\"0x10\")",
470
testcases[tc++] = new TestCase( SECTION,
471
"parseInt(\"0x10\",10)",
473
parseInt("0x10",10) );
475
testcases[tc++] = new TestCase( SECTION,
476
"parseInt(\"0022\")",
480
testcases[tc++] = new TestCase( SECTION,
481
"parseInt(\"0022\",10)",
483
parseInt("0022",10) );
485
testcases[tc++] = new TestCase( SECTION,
486
"parseInt(\"0x1000000000000080\")",
488
parseInt("0x1000000000000080") );
490
testcases[tc++] = new TestCase( SECTION,
491
"parseInt(\"0x1000000000000081\")",
493
parseInt("0x1000000000000081") );
496
"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
498
testcases[tc++] = new TestCase( SECTION, "s = "+
499
"\"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+
501
"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
505
testcases[tc++] = new TestCase( SECTION, "s +="+
506
"\"0000000000000000000000000000000000000\"; s",
507
"0xFFFFFFFFFFFFF800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
508
s += "0000000000000000000000000000000000000" );
510
testcases[tc++] = new TestCase( SECTION, "-s",
511
-1.7976931348623157e+308,
515
"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
517
testcases[tc++] = new TestCase( SECTION, "s ="+
518
"\"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+
520
"0xFFFFFFFFFFFFF80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
523
testcases[tc++] = new TestCase( SECTION,
524
"s += \"0000000000000000000000000000000000001\"",
525
"0xFFFFFFFFFFFFF800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
526
s += "0000000000000000000000000000000000001" );
528
testcases[tc++] = new TestCase( SECTION,
530
-1.7976931348623157e+308,
534
"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
536
testcases[tc++] = new TestCase( SECTION,
538
"\"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";"+
540
"0xFFFFFFFFFFFFFC0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
544
testcases[tc++] = new TestCase( SECTION,
545
"s += \"0000000000000000000000000000000000000\"",
546
"0xFFFFFFFFFFFFFC00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
547
s += "0000000000000000000000000000000000000");
550
testcases[tc++] = new TestCase( SECTION,
556
"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
558
testcases[tc++] = new TestCase( SECTION,
560
"\"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\";s",
561
"0xFFFFFFFFFFFFFB0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
564
testcases[tc++] = new TestCase( SECTION,
565
"s += \"0000000000000000000000000000000000001\"",
566
"0xFFFFFFFFFFFFFB00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
567
s += "0000000000000000000000000000000000001" );
569
testcases[tc++] = new TestCase( SECTION,
571
-1.7976931348623157e+308,
574
testcases[tc++] = new TestCase( SECTION,
576
"0xFFFFFFFFFFFFFB000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010",
579
testcases[tc++] = new TestCase( SECTION,
584
testcases[tc++] = new TestCase( SECTION,
589
testcases[tc++] = new TestCase( SECTION,
594
testcases[tc++] = new TestCase( SECTION,
599
testcases[tc++] = new TestCase( SECTION,
604
testcases[tc++] = new TestCase( SECTION,
609
testcases[tc++] = new TestCase( SECTION,
614
testcases[tc++] = new TestCase( SECTION,
619
testcases[tc++] = new TestCase( SECTION,
624
testcases[tc++] = new TestCase( SECTION,
629
testcases[tc++] = new TestCase( SECTION,
634
testcases[tc++] = new TestCase( SECTION,
639
testcases[tc++] = new TestCase( SECTION,
645
testcases[tc++] = new TestCase( SECTION,
650
testcases[tc++] = new TestCase( SECTION,
655
testcases[tc++] = new TestCase( SECTION,
660
testcases[tc++] = new TestCase( SECTION,
661
"- -\"0x100000000\"",
665
testcases[tc++] = new TestCase( SECTION,
666
"- \"-0x123456789abcde8\"",
668
- "-0x123456789abcde8" );
670
// the following two tests are not strictly ECMA 1.0
672
testcases[tc++] = new TestCase( SECTION,
673
"-\"\\u20001234\\u2001\"",
675
-"\u20001234\u2001" );
677
testcases[tc++] = new TestCase( SECTION,
678
"-\"\\u20001234\\0\"",
682
testcases[tc++] = new TestCase( SECTION,
687
testcases[tc++] = new TestCase( SECTION,
692
testcases[tc++] = new TestCase( SECTION,
697
testcases[tc++] = new TestCase( SECTION,
702
testcases[tc++] = new TestCase( SECTION,
707
testcases[tc++] = new TestCase( SECTION,
715
for ( tc=0; tc < testcases.length; tc++ ) {
716
testcases[tc].passed = writeTestCaseResult(
717
testcases[tc].expect,
718
testcases[tc].actual,
719
testcases[tc].description +" = "+
720
testcases[tc].actual );
722
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
725
return ( testcases );