1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = '11.9.2.js';
43 ECMA Section: 11.9.2 The equals operator ( == )
46 The production EqualityExpression:
47 EqualityExpression == RelationalExpression is evaluated as follows:
49 1. Evaluate EqualityExpression.
50 2. Call GetValue(Result(1)).
51 3. Evaluate RelationalExpression.
52 4. Call GetValue(Result(3)).
53 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3)
55 Author: christine@netscape.com
56 Date: 12 november 1997
58 var SECTION = "11.9.2";
59 var VERSION = "ECMA_1";
60 var BUGNUMBER="77391";
63 writeHeaderToLog( SECTION + " The equals operator ( == )");
65 // type x and type y are the same. if type x is undefined or null, return true
67 new TestCase( SECTION, "void 0 == void 0", false, void 0 != void 0 );
68 new TestCase( SECTION, "null == null", false, null != null );
70 // if x is NaN, return false. if y is NaN, return false.
72 new TestCase( SECTION, "NaN != NaN", true, Number.NaN != Number.NaN );
73 new TestCase( SECTION, "NaN != 0", true, Number.NaN != 0 );
74 new TestCase( SECTION, "0 != NaN", true, 0 != Number.NaN );
75 new TestCase( SECTION, "NaN != Infinity", true, Number.NaN != Number.POSITIVE_INFINITY );
76 new TestCase( SECTION, "Infinity != NaN", true, Number.POSITIVE_INFINITY != Number.NaN );
78 // if x is the same number value as y, return true.
80 new TestCase( SECTION, "Number.MAX_VALUE != Number.MAX_VALUE", false, Number.MAX_VALUE != Number.MAX_VALUE );
81 new TestCase( SECTION, "Number.MIN_VALUE != Number.MIN_VALUE", false, Number.MIN_VALUE != Number.MIN_VALUE );
82 new TestCase( SECTION, "Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY", false, Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY );
83 new TestCase( SECTION, "Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY", false, Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY );
85 // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true.
87 new TestCase( SECTION, "0 != 0", false, 0 != 0 );
88 new TestCase( SECTION, "0 != -0", false, 0 != -0 );
89 new TestCase( SECTION, "-0 != 0", false, -0 != 0 );
90 new TestCase( SECTION, "-0 != -0", false, -0 != -0 );
94 new TestCase( SECTION, "0.9 != 1", true, 0.9 != 1 );
95 new TestCase( SECTION, "0.999999 != 1", true, 0.999999 != 1 );
96 new TestCase( SECTION, "0.9999999999 != 1", true, 0.9999999999 != 1 );
97 new TestCase( SECTION, "0.9999999999999 != 1", true, 0.9999999999999 != 1 );
99 // type x and type y are the same type, but not numbers.
102 // x and y are strings. return true if x and y are exactly the same sequence of characters.
103 // otherwise, return false.
105 new TestCase( SECTION, "'hello' != 'hello'", false, "hello" != "hello" );
107 // x and y are booleans. return true if both are true or both are false.
109 new TestCase( SECTION, "true != true", false, true != true );
110 new TestCase( SECTION, "false != false", false, false != false );
111 new TestCase( SECTION, "true != false", true, true != false );
112 new TestCase( SECTION, "false != true", true, false != true );
114 // return true if x and y refer to the same object. otherwise return false.
116 new TestCase( SECTION, "new MyObject(true) != new MyObject(true)", true, new MyObject(true) != new MyObject(true) );
117 new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) );
118 new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) );
121 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") );
122 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") );
123 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") );
124 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") );
126 new TestCase( SECTION, "new Boolean(true) != new Boolean(true)", true, new Boolean(true) != new Boolean(true) );
127 new TestCase( SECTION, "new Boolean(false) != new Boolean(false)", true, new Boolean(false) != new Boolean(false) );
129 // if x is null and y is undefined, return true. if x is undefined and y is null return true.
131 new TestCase( SECTION, "null != void 0", false, null != void 0 );
132 new TestCase( SECTION, "void 0 != null", false, void 0 != null );
134 // if type(x) is Number and type(y) is string, return the result of the comparison x != ToNumber(y).
136 new TestCase( SECTION, "1 != '1'", false, 1 != '1' );
137 new TestCase( SECTION, "255 != '0xff'", false, 255 != '0xff' );
138 new TestCase( SECTION, "0 != '\r'", false, 0 != "\r" );
139 new TestCase( SECTION, "1e19 != '1e19'", false, 1e19 != "1e19" );
142 new TestCase( SECTION, "new Boolean(true) != true", false, true != new Boolean(true) );
143 new TestCase( SECTION, "new MyObject(true) != true", false, true != new MyObject(true) );
145 new TestCase( SECTION, "new Boolean(false) != false", false, new Boolean(false) != false );
146 new TestCase( SECTION, "new MyObject(false) != false", false, new MyObject(false) != false );
148 new TestCase( SECTION, "true != new Boolean(true)", false, true != new Boolean(true) );
149 new TestCase( SECTION, "true != new MyObject(true)", false, true != new MyObject(true) );
151 new TestCase( SECTION, "false != new Boolean(false)", false, false != new Boolean(false) );
152 new TestCase( SECTION, "false != new MyObject(false)", false, false != new MyObject(false) );
156 function MyObject( value ) {
158 this.valueOf = new Function( "return this.value" );