1ef9b1379dae64971ba7fdb2ba74ae6941f1f391
[WebKit-https.git] / LayoutTests / fast / js / resources / number-toString.js
1 var posInf = 1/0;
2 var negInf = -1/0;
3 var nan = 0/0;
4
5 shouldBeEqualToString("(0.0).toString(4)", "0");
6 shouldBeEqualToString("(-0.0).toString(4)", "0");
7 shouldBeEqualToString("(0.0).toString()", "0");
8 shouldBeEqualToString("(-0.0).toString()", "0");
9
10 // From http://bugs.webkit.org/show_bug.cgi?id=5258
11 shouldBeEqualToString("(1234.567).toString()", "1234.567");
12 shouldThrow("(1234.567).toString(0)");
13 // 0 equivilents
14 shouldThrow("(1234.567).toString(null)");
15 shouldThrow("(1234.567).toString(false)");
16 shouldThrow("(1234.567).toString('foo')");
17 shouldThrow("(1234.567).toString(nan)"); // nan is treated like 0
18
19 shouldThrow("(1234.567).toString(1)");
20 shouldThrow("(1234.567).toString(true)");
21 shouldThrow("(1234.567).toString('1')");
22
23 // These test for Firefox compatibility, the spec is "implementation defined"
24 shouldBeEqualToString("(1234.567).toString(3)", "1200201.120022100021001021021002202");
25 shouldBeEqualToString("(1234.567).toString(4)", "103102.21010212322113203111");
26 shouldBeEqualToString("(1234.567).toString(5)", "14414.240414141414141414");
27 shouldBeEqualToString("(1234.567).toString(6)", "5414.32224554134430233");
28 shouldBeEqualToString("(1234.567).toString(7)", "3412.365323661111653");
29 shouldBeEqualToString("(1234.567).toString(8)", "2322.44223351361524");
30 shouldBeEqualToString("(1234.567).toString(9)", "1621.50830703723265");
31 shouldBeEqualToString("(1234.567).toString(10)", "1234.567");
32 shouldBeEqualToString("(1234.567).toString(11)", "a22.62674a0a5885");
33 shouldBeEqualToString("(1234.567).toString(12)", "86a.697938b17701");
34 shouldBeEqualToString("(1234.567).toString(13)", "73c.74a91191a65");
35 shouldBeEqualToString("(1234.567).toString(14)", "642.7d1bc2caa757");
36 shouldBeEqualToString("(1234.567).toString(15)", "574.87895959596");
37 shouldBeEqualToString("(1234.567).toString(16)", "4d2.9126e978d5");
38 shouldBeEqualToString("(1234.567).toString(17)", "44a.9aeb6faa0da");
39 shouldBeEqualToString("(1234.567).toString(18)", "3ea.a3cd7102ac");
40 shouldBeEqualToString("(1234.567).toString(19)", "37i.aed102a04d");
41 shouldBeEqualToString("(1234.567).toString(20)", "31e.b6g");
42 shouldBeEqualToString("(1234.567).toString(21)", "2gg.bj0kf5cfe9");
43 shouldBeEqualToString("(1234.567).toString(22)", "2c2.ca9937cak");
44 shouldBeEqualToString("(1234.567).toString(23)", "27f.d0lfjb1a7c");
45 shouldBeEqualToString("(1234.567).toString(24)", "23a.dee4nj99j");
46 shouldBeEqualToString("(1234.567).toString(25)", "1o9.e49999999");
47 shouldBeEqualToString("(1234.567).toString(26)", "1lc.ej7fa4pkf");
48 shouldBeEqualToString("(1234.567).toString(27)", "1ij.f8971772k");
49 shouldBeEqualToString("(1234.567).toString(28)", "1g2.foelqia8e");
50 shouldBeEqualToString("(1234.567).toString(29)", "1dg.gcog9e05q");
51 shouldBeEqualToString("(1234.567).toString(30)", "1b4.h09");
52 shouldBeEqualToString("(1234.567).toString(31)", "18p.hhrfcj3t");
53 shouldBeEqualToString("(1234.567).toString(32)", "16i.i4jeiu6l");
54 shouldBeEqualToString("(1234.567).toString(33)", "14d.inf96rdvm");
55 shouldBeEqualToString("(1234.567).toString(34)", "12a.j9fchdtm");
56 shouldBeEqualToString("(1234.567).toString(35)", "109.jtk4d4d4e");
57 shouldBeEqualToString("(1234.567).toString(36)", "ya.kety9sifl");
58
59 shouldThrow("(1234.567).toString(37)");
60 shouldThrow("(1234.567).toString(-1)");
61 shouldThrow("(1234.567).toString(posInf)");
62 shouldThrow("(1234.567).toString(negInf)");
63
64 shouldBeEqualToString("posInf.toString()", "Infinity");
65 shouldBeEqualToString("negInf.toString()", "-Infinity");
66 shouldBeEqualToString("nan.toString()", "NaN");
67
68 var successfullyParsed = true;