Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | function add(a, b) { |
| 29 | return a + b; |
| 30 | } |
| 31 | |
| 32 | function testToString(a, b) { |
| 33 | assertEquals(a, b.toString()); |
| 34 | assertEquals(a, "" + b); |
| 35 | assertEquals(a, add("", b)); |
| 36 | assertEquals("yes" + a, add("yes", b)); |
| 37 | } |
| 38 | |
| 39 | testToString("NaN", (NaN)); |
| 40 | testToString("Infinity", (1/0)); |
| 41 | testToString("-Infinity", (-1/0)); |
| 42 | testToString("0", (0)); |
| 43 | testToString("9", (9)); |
| 44 | testToString("90", (90)); |
| 45 | testToString("90.12", (90.12)); |
| 46 | testToString("0.1", (0.1)); |
| 47 | testToString("0.01", (0.01)); |
| 48 | testToString("0.0123", (0.0123)); |
| 49 | testToString("111111111111111110000", (111111111111111111111)); |
| 50 | testToString("1.1111111111111111e+21", (1111111111111111111111)); |
| 51 | testToString("1.1111111111111111e+22", (11111111111111111111111)); |
| 52 | testToString("0.00001", (0.00001)); |
| 53 | testToString("0.000001", (0.000001)); |
| 54 | testToString("1e-7", (0.0000001)); |
| 55 | testToString("1.2e-7", (0.00000012)); |
| 56 | testToString("1.23e-7", (0.000000123)); |
| 57 | testToString("1e-8", (0.00000001)); |
| 58 | testToString("1.2e-8", (0.000000012)); |
| 59 | testToString("1.23e-8", (0.0000000123)); |
| 60 | |
| 61 | testToString("0", (-0)); |
| 62 | testToString("-9", (-9)); |
| 63 | testToString("-90", (-90)); |
| 64 | testToString("-90.12", (-90.12)); |
| 65 | testToString("-0.1", (-0.1)); |
| 66 | testToString("-0.01", (-0.01)); |
| 67 | testToString("-0.0123", (-0.0123)); |
| 68 | testToString("-111111111111111110000", (-111111111111111111111)); |
| 69 | testToString("-1.1111111111111111e+21", (-1111111111111111111111)); |
| 70 | testToString("-1.1111111111111111e+22", (-11111111111111111111111)); |
| 71 | testToString("-0.00001", (-0.00001)); |
| 72 | testToString("-0.000001", (-0.000001)); |
| 73 | testToString("-1e-7", (-0.0000001)); |
| 74 | testToString("-1.2e-7", (-0.00000012)); |
| 75 | testToString("-1.23e-7", (-0.000000123)); |
| 76 | testToString("-1e-8", (-0.00000001)); |
| 77 | testToString("-1.2e-8", (-0.000000012)); |
| 78 | testToString("-1.23e-8", (-0.0000000123)); |
| 79 | |
| 80 | testToString("1000", (1000)); |
| 81 | testToString("0.00001", (0.00001)); |
| 82 | testToString("1000000000000000100", (1000000000000000128)); |
| 83 | testToString("1e+21", (1000000000000000012800)); |
| 84 | testToString("-1e+21", (-1000000000000000012800)); |
| 85 | testToString("1e-7", (0.0000001)); |
| 86 | testToString("-1e-7", (-0.0000001)); |
| 87 | testToString("1.0000000000000001e+21", (1000000000000000128000)); |
| 88 | testToString("0.000001", (0.000001)); |
| 89 | testToString("1e-7", (0.0000001)); |