blob: 41d3cbd525058ac2429a169bc9614e2efa96a6d8 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
28function add(a, b) {
29 return a + b;
30}
31
32function 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
39testToString("NaN", (NaN));
40testToString("Infinity", (1/0));
41testToString("-Infinity", (-1/0));
42testToString("0", (0));
43testToString("9", (9));
44testToString("90", (90));
45testToString("90.12", (90.12));
46testToString("0.1", (0.1));
47testToString("0.01", (0.01));
48testToString("0.0123", (0.0123));
49testToString("111111111111111110000", (111111111111111111111));
50testToString("1.1111111111111111e+21", (1111111111111111111111));
51testToString("1.1111111111111111e+22", (11111111111111111111111));
52testToString("0.00001", (0.00001));
53testToString("0.000001", (0.000001));
54testToString("1e-7", (0.0000001));
55testToString("1.2e-7", (0.00000012));
56testToString("1.23e-7", (0.000000123));
57testToString("1e-8", (0.00000001));
58testToString("1.2e-8", (0.000000012));
59testToString("1.23e-8", (0.0000000123));
60
61testToString("0", (-0));
62testToString("-9", (-9));
63testToString("-90", (-90));
64testToString("-90.12", (-90.12));
65testToString("-0.1", (-0.1));
66testToString("-0.01", (-0.01));
67testToString("-0.0123", (-0.0123));
68testToString("-111111111111111110000", (-111111111111111111111));
69testToString("-1.1111111111111111e+21", (-1111111111111111111111));
70testToString("-1.1111111111111111e+22", (-11111111111111111111111));
71testToString("-0.00001", (-0.00001));
72testToString("-0.000001", (-0.000001));
73testToString("-1e-7", (-0.0000001));
74testToString("-1.2e-7", (-0.00000012));
75testToString("-1.23e-7", (-0.000000123));
76testToString("-1e-8", (-0.00000001));
77testToString("-1.2e-8", (-0.000000012));
78testToString("-1.23e-8", (-0.0000000123));
79
80testToString("1000", (1000));
81testToString("0.00001", (0.00001));
82testToString("1000000000000000100", (1000000000000000128));
83testToString("1e+21", (1000000000000000012800));
84testToString("-1e+21", (-1000000000000000012800));
85testToString("1e-7", (0.0000001));
86testToString("-1e-7", (-0.0000001));
87testToString("1.0000000000000001e+21", (1000000000000000128000));
88testToString("0.000001", (0.000001));
89testToString("1e-7", (0.0000001));