michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 11.9.2.js michael@0: ECMA Section: 11.9.2 The equals operator ( == ) michael@0: Description: michael@0: michael@0: The production EqualityExpression: michael@0: EqualityExpression == RelationalExpression is evaluated as follows: michael@0: michael@0: 1. Evaluate EqualityExpression. michael@0: 2. Call GetValue(Result(1)). michael@0: 3. Evaluate RelationalExpression. michael@0: 4. Call GetValue(Result(3)). michael@0: 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3) michael@0: 6. Return Result(5). michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "11.9.2"; michael@0: var VERSION = "ECMA_1"; michael@0: var BUGNUMBER="77391"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " The equals operator ( == )"); michael@0: michael@0: // type x and type y are the same. if type x is undefined or null, return true michael@0: michael@0: new TestCase( SECTION, "void 0 == void 0", false, void 0 != void 0 ); michael@0: new TestCase( SECTION, "null == null", false, null != null ); michael@0: michael@0: // if x is NaN, return false. if y is NaN, return false. michael@0: michael@0: new TestCase( SECTION, "NaN != NaN", true, Number.NaN != Number.NaN ); michael@0: new TestCase( SECTION, "NaN != 0", true, Number.NaN != 0 ); michael@0: new TestCase( SECTION, "0 != NaN", true, 0 != Number.NaN ); michael@0: new TestCase( SECTION, "NaN != Infinity", true, Number.NaN != Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "Infinity != NaN", true, Number.POSITIVE_INFINITY != Number.NaN ); michael@0: michael@0: // if x is the same number value as y, return true. michael@0: michael@0: new TestCase( SECTION, "Number.MAX_VALUE != Number.MAX_VALUE", false, Number.MAX_VALUE != Number.MAX_VALUE ); michael@0: new TestCase( SECTION, "Number.MIN_VALUE != Number.MIN_VALUE", false, Number.MIN_VALUE != Number.MIN_VALUE ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY", false, Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY", false, Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY ); michael@0: michael@0: // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true. michael@0: michael@0: new TestCase( SECTION, "0 != 0", false, 0 != 0 ); michael@0: new TestCase( SECTION, "0 != -0", false, 0 != -0 ); michael@0: new TestCase( SECTION, "-0 != 0", false, -0 != 0 ); michael@0: new TestCase( SECTION, "-0 != -0", false, -0 != -0 ); michael@0: michael@0: // return false. michael@0: michael@0: new TestCase( SECTION, "0.9 != 1", true, 0.9 != 1 ); michael@0: new TestCase( SECTION, "0.999999 != 1", true, 0.999999 != 1 ); michael@0: new TestCase( SECTION, "0.9999999999 != 1", true, 0.9999999999 != 1 ); michael@0: new TestCase( SECTION, "0.9999999999999 != 1", true, 0.9999999999999 != 1 ); michael@0: michael@0: // type x and type y are the same type, but not numbers. michael@0: michael@0: michael@0: // x and y are strings. return true if x and y are exactly the same sequence of characters. michael@0: // otherwise, return false. michael@0: michael@0: new TestCase( SECTION, "'hello' != 'hello'", false, "hello" != "hello" ); michael@0: michael@0: // x and y are booleans. return true if both are true or both are false. michael@0: michael@0: new TestCase( SECTION, "true != true", false, true != true ); michael@0: new TestCase( SECTION, "false != false", false, false != false ); michael@0: new TestCase( SECTION, "true != false", true, true != false ); michael@0: new TestCase( SECTION, "false != true", true, false != true ); michael@0: michael@0: // return true if x and y refer to the same object. otherwise return false. michael@0: michael@0: new TestCase( SECTION, "new MyObject(true) != new MyObject(true)", true, new MyObject(true) != new MyObject(true) ); michael@0: new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) ); michael@0: new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) ); michael@0: michael@0: michael@0: new TestCase( SECTION, "x = new MyObject(true); y = x; z = x; z != y", false, eval("x = new MyObject(true); y = x; z = x; z != y") ); michael@0: new TestCase( SECTION, "x = new MyObject(false); y = x; z = x; z != y", false, eval("x = new MyObject(false); y = x; z = x; z != y") ); michael@0: new TestCase( SECTION, "x = new Boolean(true); y = x; z = x; z != y", false, eval("x = new Boolean(true); y = x; z = x; z != y") ); michael@0: new TestCase( SECTION, "x = new Boolean(false); y = x; z = x; z != y", false, eval("x = new Boolean(false); y = x; z = x; z != y") ); michael@0: michael@0: new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) ); michael@0: new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) ); michael@0: michael@0: // if x is null and y is undefined, return true. if x is undefined and y is null return true. michael@0: michael@0: new TestCase( SECTION, "null != void 0", false, null != void 0 ); michael@0: new TestCase( SECTION, "void 0 != null", false, void 0 != null ); michael@0: michael@0: // if type(x) is Number and type(y) is string, return the result of the comparison x != ToNumber(y). michael@0: michael@0: new TestCase( SECTION, "1 != '1'", false, 1 != '1' ); michael@0: new TestCase( SECTION, "255 != '0xff'", false, 255 != '0xff' ); michael@0: new TestCase( SECTION, "0 != '\r'", false, 0 != "\r" ); michael@0: new TestCase( SECTION, "1e19 != '1e19'", false, 1e19 != "1e19" ); michael@0: michael@0: michael@0: new TestCase( SECTION, "new Boolean(true) != true", false, true != new Boolean(true) ); michael@0: new TestCase( SECTION, "new MyObject(true) != true", false, true != new MyObject(true) ); michael@0: michael@0: new TestCase( SECTION, "new Boolean(false) != false", false, new Boolean(false) != false ); michael@0: new TestCase( SECTION, "new MyObject(false) != false", false, new MyObject(false) != false ); michael@0: michael@0: new TestCase( SECTION, "true != new Boolean(true)", false, true != new Boolean(true) ); michael@0: new TestCase( SECTION, "true != new MyObject(true)", false, true != new MyObject(true) ); michael@0: michael@0: new TestCase( SECTION, "false != new Boolean(false)", false, false != new Boolean(false) ); michael@0: new TestCase( SECTION, "false != new MyObject(false)", false, false != new MyObject(false) ); michael@0: michael@0: test(); michael@0: michael@0: function MyObject( value ) { michael@0: this.value = value; michael@0: this.valueOf = new Function( "return this.value" ); michael@0: }