1// Copyright 2008 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/**
29 * This test uses assert{True,False}(... == ...) instead of
30 * assertEquals(..., ...) to not rely on the details of the
31 * implementation of assertEquals.
32 */
33
34assertTrue (void 0 == void 0, "void 0 == void 0");
35assertTrue (null == null,     "null == null");
36assertFalse(NaN == NaN,       "NaN == NaN");
37assertFalse(NaN == 0,         "NaN == 0");
38assertFalse(0 == NaN,         "0 == NaN");
39assertFalse(NaN == Infinity,  "NaN == Inf");
40assertFalse(Infinity == NaN,  "Inf == NaN");
41
42assertTrue(Number.MAX_VALUE == Number.MAX_VALUE, "MAX == MAX");
43assertTrue(Number.MIN_VALUE == Number.MIN_VALUE, "MIN == MIN");
44assertTrue(Infinity == Infinity,                 "Inf == Inf");
45assertTrue(-Infinity == -Infinity,               "-Inf == -Inf");
46
47assertTrue(0 == 0,   "0 == 0");
48assertTrue(0 == -0,  "0 == -0");
49assertTrue(-0 == 0,  "-0 == 0");
50assertTrue(-0 == -0, "-0 == -0");
51
52assertFalse(0.9 == 1,             "0.9 == 1");
53assertFalse(0.999999 == 1,        "0.999999 == 1");
54assertFalse(0.9999999999 == 1,    "0.9999999999 == 1");
55assertFalse(0.9999999999999 == 1, "0.9999999999999 == 1");
56
57assertTrue('hello' == 'hello', "'hello' == 'hello'");
58
59assertTrue (true == true,   "true == true");
60assertTrue (false == false, "false == false");
61assertFalse(true == false,  "true == false");
62assertFalse(false == true,  "false == true");
63
64assertFalse(new Wrapper(null) == new Wrapper(null),   "new Wrapper(null) == new Wrapper(null)");
65assertFalse(new Boolean(true) == new Boolean(true),   "new Boolean(true) == new Boolean(true)");
66assertFalse(new Boolean(false) == new Boolean(false), "new Boolean(false) == new Boolean(false)");
67
68(function () {
69  var x = new Wrapper(null);
70  var y = x, z = x;
71  assertTrue(y == x);
72})();
73
74(function () {
75  var x = new Boolean(true);
76  var y = x, z = x;
77  assertTrue(y == x);
78})();
79
80(function () {
81  var x = new Boolean(false);
82  var y = x, z = x;
83  assertTrue(y == x);
84})();
85
86assertTrue(null == void 0,             "null == void 0");
87assertTrue(void 0 == null,             "void 0 == null");
88assertFalse(new Wrapper(null) == null, "new Wrapper(null) == null");
89assertFalse(null == new Wrapper(null), "null == new Wrapper(null)");
90
91assertTrue(1 == '1',       "1 == '1");
92assertTrue(255 == '0xff',  "255 == '0xff'");
93assertTrue(0 == '\r',      "0 == '\\r'");
94assertTrue(1e19 == '1e19', "1e19 == '1e19'");
95
96assertTrue(new Boolean(true) == true,   "new Boolean(true) == true");
97assertTrue(new Boolean(false) == false, "new Boolean(false) == false");
98assertTrue(true == new Boolean(true),   "true == new Boolean(true)");
99assertTrue(false == new Boolean(false), "false == new Boolean(false)");
100
101assertTrue(Boolean(true) == true,   "Boolean(true) == true");
102assertTrue(Boolean(false) == false, "Boolean(false) == false");
103assertTrue(true == Boolean(true),   "true == Boolean(true)");
104assertTrue(false == Boolean(false), "false == Boolean(false)");
105
106assertTrue(new Wrapper(true) == true,   "new Wrapper(true) == true");
107assertTrue(new Wrapper(false) == false, "new Wrapper(false) == false");
108assertTrue(true == new Wrapper(true),   "true = new Wrapper(true)");
109assertTrue(false == new Wrapper(false), "false = new Wrapper(false)");
110
111function Wrapper(value) {
112  this.value = value;
113  this.valueOf = function () { return this.value; };
114}
115