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 34 assertTrue (void 0 == void 0, "void 0 == void 0"); 35 assertTrue (null == null, "null == null"); 36 assertFalse(NaN == NaN, "NaN == NaN"); 37 assertFalse(NaN == 0, "NaN == 0"); 38 assertFalse(0 == NaN, "0 == NaN"); 39 assertFalse(NaN == Infinity, "NaN == Inf"); 40 assertFalse(Infinity == NaN, "Inf == NaN"); 41 42 assertTrue(Number.MAX_VALUE == Number.MAX_VALUE, "MAX == MAX"); 43 assertTrue(Number.MIN_VALUE == Number.MIN_VALUE, "MIN == MIN"); 44 assertTrue(Infinity == Infinity, "Inf == Inf"); 45 assertTrue(-Infinity == -Infinity, "-Inf == -Inf"); 46 47 assertTrue(0 == 0, "0 == 0"); 48 assertTrue(0 == -0, "0 == -0"); 49 assertTrue(-0 == 0, "-0 == 0"); 50 assertTrue(-0 == -0, "-0 == -0"); 51 52 assertFalse(0.9 == 1, "0.9 == 1"); 53 assertFalse(0.999999 == 1, "0.999999 == 1"); 54 assertFalse(0.9999999999 == 1, "0.9999999999 == 1"); 55 assertFalse(0.9999999999999 == 1, "0.9999999999999 == 1"); 56 57 assertTrue('hello' == 'hello', "'hello' == 'hello'"); 58 59 assertTrue (true == true, "true == true"); 60 assertTrue (false == false, "false == false"); 61 assertFalse(true == false, "true == false"); 62 assertFalse(false == true, "false == true"); 63 64 assertFalse(new Wrapper(null) == new Wrapper(null), "new Wrapper(null) == new Wrapper(null)"); 65 assertFalse(new Boolean(true) == new Boolean(true), "new Boolean(true) == new Boolean(true)"); 66 assertFalse(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 86 assertTrue(null == void 0, "null == void 0"); 87 assertTrue(void 0 == null, "void 0 == null"); 88 assertFalse(new Wrapper(null) == null, "new Wrapper(null) == null"); 89 assertFalse(null == new Wrapper(null), "null == new Wrapper(null)"); 90 91 assertTrue(1 == '1', "1 == '1"); 92 assertTrue(255 == '0xff', "255 == '0xff'"); 93 assertTrue(0 == '\r', "0 == '\\r'"); 94 assertTrue(1e19 == '1e19', "1e19 == '1e19'"); 95 96 assertTrue(new Boolean(true) == true, "new Boolean(true) == true"); 97 assertTrue(new Boolean(false) == false, "new Boolean(false) == false"); 98 assertTrue(true == new Boolean(true), "true == new Boolean(true)"); 99 assertTrue(false == new Boolean(false), "false == new Boolean(false)"); 100 101 assertTrue(Boolean(true) == true, "Boolean(true) == true"); 102 assertTrue(Boolean(false) == false, "Boolean(false) == false"); 103 assertTrue(true == Boolean(true), "true == Boolean(true)"); 104 assertTrue(false == Boolean(false), "false == Boolean(false)"); 105 106 assertTrue(new Wrapper(true) == true, "new Wrapper(true) == true"); 107 assertTrue(new Wrapper(false) == false, "new Wrapper(false) == false"); 108 assertTrue(true == new Wrapper(true), "true = new Wrapper(true)"); 109 assertTrue(false == new Wrapper(false), "false = new Wrapper(false)"); 110 111 function Wrapper(value) { 112 this.value = value; 113 this.valueOf = function () { return this.value; }; 114 } 115