OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the |
| 11 // documentation and/or other materials provided with the distribution. |
| 12 // |
| 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
| 24 var posInf = 1/0; |
| 25 var negInf = -1/0; |
| 26 var nan = 0/0; |
| 27 |
| 28 shouldBeEqualToString("(0.0).toString(4)", "0"); |
| 29 shouldBeEqualToString("(-0.0).toString(4)", "0"); |
| 30 shouldBeEqualToString("(0.0).toString()", "0"); |
| 31 shouldBeEqualToString("(-0.0).toString()", "0"); |
| 32 |
| 33 // From http://bugs.webkit.org/show_bug.cgi?id=5258 |
| 34 shouldBeEqualToString("(1234.567).toString()", "1234.567"); |
| 35 shouldThrow("(1234.567).toString(0)"); |
| 36 // 0 equivilents |
| 37 shouldThrow("(1234.567).toString(null)"); |
| 38 shouldThrow("(1234.567).toString(false)"); |
| 39 shouldThrow("(1234.567).toString('foo')"); |
| 40 shouldThrow("(1234.567).toString(nan)"); // nan is treated like 0 |
| 41 |
| 42 shouldThrow("(1234.567).toString(1)"); |
| 43 shouldThrow("(1234.567).toString(true)"); |
| 44 shouldThrow("(1234.567).toString('1')"); |
| 45 |
| 46 // These test for Firefox compatibility, the spec is "implementation defined" |
| 47 shouldBeEqualToString("(1234.567).toString(2)", "10011010010.1001000100100110111
010010111100011010101"); |
| 48 shouldBeEqualToString("(1234.567).toString(3)", "1200201.12002210002100102102100
2202"); |
| 49 shouldBeEqualToString("(1234.567).toString(4)", "103102.21010212322113203111"); |
| 50 shouldBeEqualToString("(1234.567).toString(4.9)", "103102.21010212322113203111")
; |
| 51 shouldBeEqualToString("(1234.567).toString(5)", "14414.240414141414141414"); |
| 52 shouldBeEqualToString("(1234.567).toString(6)", "5414.32224554134430233"); |
| 53 shouldBeEqualToString("(1234.567).toString(7)", "3412.365323661111653"); |
| 54 shouldBeEqualToString("(1234.567).toString(8)", "2322.44223351361524"); |
| 55 shouldBeEqualToString("(1234.567).toString(9)", "1621.50830703723265"); |
| 56 shouldBeEqualToString("(1234.567).toString(10)", "1234.567"); |
| 57 shouldBeEqualToString("(1234.567).toString(11)", "a22.62674a0a5885"); |
| 58 shouldBeEqualToString("(1234.567).toString(12)", "86a.697938b17701"); |
| 59 shouldBeEqualToString("(1234.567).toString(13)", "73c.74a91191a65"); |
| 60 shouldBeEqualToString("(1234.567).toString(14)", "642.7d1bc2caa757"); |
| 61 shouldBeEqualToString("(1234.567).toString(15)", "574.87895959596"); |
| 62 shouldBeEqualToString("(1234.567).toString(16)", "4d2.9126e978d5"); |
| 63 shouldBeEqualToString("(1234.567).toString(17)", "44a.9aeb6faa0da"); |
| 64 shouldBeEqualToString("(1234.567).toString(18)", "3ea.a3cd7102ac"); |
| 65 shouldBeEqualToString("(1234.567).toString(19)", "37i.aed102a04d"); |
| 66 shouldBeEqualToString("(1234.567).toString(20)", "31e.b6g"); |
| 67 shouldBeEqualToString("(1234.567).toString(21)", "2gg.bj0kf5cfe9"); |
| 68 shouldBeEqualToString("(1234.567).toString(22)", "2c2.ca9937cak"); |
| 69 shouldBeEqualToString("(1234.567).toString(23)", "27f.d0lfjb1a7c"); |
| 70 shouldBeEqualToString("(1234.567).toString(24)", "23a.dee4nj99j"); |
| 71 shouldBeEqualToString("(1234.567).toString(25)", "1o9.e49999999"); |
| 72 shouldBeEqualToString("(1234.567).toString(26)", "1lc.ej7fa4pkf"); |
| 73 shouldBeEqualToString("(1234.567).toString(27)", "1ij.f8971772k"); |
| 74 shouldBeEqualToString("(1234.567).toString(28)", "1g2.foelqia8e"); |
| 75 shouldBeEqualToString("(1234.567).toString(29)", "1dg.gcog9e05q"); |
| 76 shouldBeEqualToString("(1234.567).toString(30)", "1b4.h09"); |
| 77 shouldBeEqualToString("(1234.567).toString(31)", "18p.hhrfcj3t"); |
| 78 shouldBeEqualToString("(1234.567).toString(32)", "16i.i4jeiu6l"); |
| 79 shouldBeEqualToString("(1234.567).toString(33)", "14d.inf96rdvm"); |
| 80 shouldBeEqualToString("(1234.567).toString(34)", "12a.j9fchdtm"); |
| 81 shouldBeEqualToString("(1234.567).toString(35)", "109.jtk4d4d4e"); |
| 82 shouldBeEqualToString("(1234.567).toString(36)", "ya.kety9sifl"); |
| 83 |
| 84 shouldThrow("(1234.567).toString(37)"); |
| 85 shouldThrow("(1234.567).toString(-1)"); |
| 86 shouldThrow("(1234.567).toString(posInf)"); |
| 87 shouldThrow("(1234.567).toString(negInf)"); |
| 88 |
| 89 shouldBeEqualToString("posInf.toString()", "Infinity"); |
| 90 shouldBeEqualToString("negInf.toString()", "-Infinity"); |
| 91 shouldBeEqualToString("nan.toString()", "NaN"); |
| 92 |
| 93 shouldBeEqualToString('"" + -0.0', "0"); |
OLD | NEW |