1// Copyright 2009 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
28assertEquals("ab", "a" + "b", "ll");
29
30assertEquals("12", "1" + "2", "dd");
31assertEquals("123", "1" + "2" + "3", "ddd");
32assertEquals("123", 1 + "2" + "3", "ndd");
33assertEquals("123", "1" + 2 + "3", "dnd");
34assertEquals("123", "1" + "2" + 3, "ddn");
35
36assertEquals("123", "1" + 2 + 3, "dnn");
37assertEquals("123", 1 + "2" + 3, "ndn");
38assertEquals("33", 1 + 2 + "3", "nnd");
39
40var x = "1";
41assertEquals("12", x + 2, "vn");
42assertEquals("12", x + "2", "vd");
43assertEquals("21", 2 + x, "nv");
44assertEquals("21", "2" + x, "dv");
45
46var y = "2";
47assertEquals("12", x + y, "vdvd");
48
49x = 1;
50assertEquals("12", x + y, "vnvd");
51
52y = 2;
53assertEquals(3, x + y, "vnvn");
54
55x = "1";
56assertEquals("12", x + y, "vdvn");
57
58y = "2";
59assertEquals("12", x + y, "vdvd2");
60
61(function(x, y) {
62  var z = "3";
63  var w = "4";
64
65  assertEquals("11", x + x, "xx");
66  assertEquals("12", x + y, "xy");
67  assertEquals("13", x + z, "xz");
68  assertEquals("14", x + w, "xw");
69
70  assertEquals("21", y + x, "yx");
71  assertEquals("22", y + y, "yy");
72  assertEquals("23", y + z, "yz");
73  assertEquals("24", y + w, "yw");
74
75  assertEquals("31", z + x, "zx");
76  assertEquals("32", z + y, "zy");
77  assertEquals("33", z + z, "zz");
78  assertEquals("34", z + w, "zw");
79
80  assertEquals("41", w + x, "wx");
81  assertEquals("42", w + y, "wy");
82  assertEquals("43", w + z, "wz");
83  assertEquals("44", w + w, "ww");
84
85  (function(){x = 1; z = 3;})();
86
87  assertEquals(2, x + x, "x'x");
88  assertEquals("12", x + y, "x'y");
89  assertEquals(4, x + z, "x'z'");
90  assertEquals("14", x + w, "x'w");
91
92  assertEquals("21", y + x, "yx'");
93  assertEquals("22", y + y, "yy");
94  assertEquals("23", y + z, "yz'");
95  assertEquals("24", y + w, "yw");
96
97  assertEquals(4, z + x, "z'x'");
98  assertEquals("32", z + y, "z'y");
99  assertEquals(6, z + z, "z'z'");
100  assertEquals("34", z + w, "z'w");
101
102  assertEquals("41", w + x, "wx'");
103  assertEquals("42", w + y, "wy");
104  assertEquals("43", w + z, "wz'");
105  assertEquals("44", w + w, "ww");
106})("1", "2");
107
108assertEquals("142", "1" + new Number(42), "sN");
109assertEquals("421", new Number(42) + "1", "Ns");
110assertEquals(84, new Number(42) + new Number(42), "NN");
111
112assertEquals("142", "1" + new String("42"), "sS");
113assertEquals("421", new String("42") + "1", "Ss");
114assertEquals("142", "1" + new String("42"), "sS");
115assertEquals("4242", new String("42") + new String("42"), "SS");
116
117assertEquals("1true", "1" + true, "sb");
118assertEquals("true1", true + "1", "bs");
119assertEquals(2, true + true, "bs");
120
121assertEquals("1true", "1" + new Boolean(true), "sB");
122assertEquals("true1", new Boolean(true) + "1", "Bs");
123assertEquals(2, new Boolean(true) + new Boolean(true), "Bs");
124
125assertEquals("1undefined", "1" + void 0, "sv");
126assertEquals("undefined1", (void 0)  + "1", "vs");
127assertTrue(isNaN(void 0 + void 0), "vv");
128
129assertEquals("1null", "1" + null, "su");
130assertEquals("null1", null + "1", "us");
131assertEquals(0, null + null, "uu");
132
133(function (i) {
134  // Check that incoming frames are merged correctly.
135  var x;
136  var y;
137  var z;
138  var w;
139  switch (i) {
140  case 1: x = 42; y = "stry"; z = "strz"; w = 42; break;
141  default: x = "strx", y = 42; z = "strz"; w = 42; break;
142  }
143  var resxx = x + x;
144  var resxy = x + y;
145  var resxz = x + z;
146  var resxw = x + w;
147  var resyx = y + x;
148  var resyy = y + y;
149  var resyz = y + z;
150  var resyw = y + w;
151  var reszx = z + x;
152  var reszy = z + y;
153  var reszz = z + z;
154  var reszw = z + w;
155  var reswx = w + x;
156  var reswy = w + y;
157  var reswz = w + z;
158  var resww = w + w;
159  assertEquals(84, resxx, "swxx");
160  assertEquals("42stry", resxy, "swxy");
161  assertEquals("42strz", resxz, "swxz");
162  assertEquals(84, resxw, "swxw");
163  assertEquals("stry42", resyx, "swyx");
164  assertEquals("strystry", resyy, "swyy");
165  assertEquals("strystrz", resyz, "swyz");
166  assertEquals("stry42", resyw, "swyw");
167  assertEquals("strz42", reszx, "swzx");
168  assertEquals("strzstry", reszy, "swzy");
169  assertEquals("strzstrz", reszz, "swzz");
170  assertEquals("strz42", reszw, "swzw");
171  assertEquals(84, reswx, "swwx");
172  assertEquals("42stry", reswy, "swwy");
173  assertEquals("42strz", reswz, "swwz");
174  assertEquals(84, resww, "swww");
175})(1);
176
177// Generate ascii and non ascii strings from length 0 to 20.
178var ascii = 'aaaaaaaaaaaaaaaaaaaa';
179var non_ascii = '\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234';
180assertEquals(20, ascii.length);
181assertEquals(20, non_ascii.length);
182var a = Array(21);
183var b = Array(21);
184for (var i = 0; i <= 20; i++) {
185  a[i] = ascii.substring(0, i);
186  b[i] = non_ascii.substring(0, i);
187}
188
189// Add ascii and non-ascii strings generating strings with length from 0 to 20.
190for (var i = 0; i <= 20; i++) {
191  for (var j = 0; j < i; j++) {
192    assertEquals(a[i], a[j] + a[i - j])
193    assertEquals(b[i], b[j] + b[i - j])
194  }
195}
196