|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 11.9.3.js |
|
9 ECMA Section: 11.9.3 The equals operator ( == ) |
|
10 Description: |
|
11 |
|
12 The production EqualityExpression: |
|
13 EqualityExpression == RelationalExpression is evaluated as follows: |
|
14 |
|
15 1. Evaluate EqualityExpression. |
|
16 2. Call GetValue(Result(1)). |
|
17 3. Evaluate RelationalExpression. |
|
18 4. Call GetValue(Result(3)). |
|
19 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3) |
|
20 6. Return Result(5). |
|
21 Author: christine@netscape.com |
|
22 Date: 12 november 1997 |
|
23 */ |
|
24 var SECTION = "11.9.3"; |
|
25 var VERSION = "ECMA_1"; |
|
26 var BUGNUMBER="77391"; |
|
27 startTest(); |
|
28 |
|
29 writeHeaderToLog( SECTION + " The equals operator ( == )"); |
|
30 |
|
31 // type x and type y are the same. if type x is undefined or null, return true |
|
32 |
|
33 new TestCase( SECTION, "void 0 = void 0", true, void 0 == void 0 ); |
|
34 new TestCase( SECTION, "null == null", true, null == null ); |
|
35 |
|
36 // if x is NaN, return false. if y is NaN, return false. |
|
37 |
|
38 new TestCase( SECTION, "NaN == NaN", false, Number.NaN == Number.NaN ); |
|
39 new TestCase( SECTION, "NaN == 0", false, Number.NaN == 0 ); |
|
40 new TestCase( SECTION, "0 == NaN", false, 0 == Number.NaN ); |
|
41 new TestCase( SECTION, "NaN == Infinity", false, Number.NaN == Number.POSITIVE_INFINITY ); |
|
42 new TestCase( SECTION, "Infinity == NaN", false, Number.POSITIVE_INFINITY == Number.NaN ); |
|
43 |
|
44 // if x is the same number value as y, return true. |
|
45 |
|
46 new TestCase( SECTION, "Number.MAX_VALUE == Number.MAX_VALUE", true, Number.MAX_VALUE == Number.MAX_VALUE ); |
|
47 new TestCase( SECTION, "Number.MIN_VALUE == Number.MIN_VALUE", true, Number.MIN_VALUE == Number.MIN_VALUE ); |
|
48 new TestCase( SECTION, "Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY", true, Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY ); |
|
49 new TestCase( SECTION, "Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY", true, Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY ); |
|
50 |
|
51 // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true. |
|
52 |
|
53 new TestCase( SECTION, "0 == 0", true, 0 == 0 ); |
|
54 new TestCase( SECTION, "0 == -0", true, 0 == -0 ); |
|
55 new TestCase( SECTION, "-0 == 0", true, -0 == 0 ); |
|
56 new TestCase( SECTION, "-0 == -0", true, -0 == -0 ); |
|
57 |
|
58 // return false. |
|
59 |
|
60 new TestCase( SECTION, "0.9 == 1", false, 0.9 == 1 ); |
|
61 new TestCase( SECTION, "0.999999 == 1", false, 0.999999 == 1 ); |
|
62 new TestCase( SECTION, "0.9999999999 == 1", false, 0.9999999999 == 1 ); |
|
63 new TestCase( SECTION, "0.9999999999999 == 1", false, 0.9999999999999 == 1 ); |
|
64 |
|
65 // type x and type y are the same type, but not numbers. |
|
66 |
|
67 |
|
68 // x and y are strings. return true if x and y are exactly the same sequence of characters. |
|
69 // otherwise, return false. |
|
70 |
|
71 new TestCase( SECTION, "'hello' == 'hello'", true, "hello" == "hello" ); |
|
72 |
|
73 // x and y are booleans. return true if both are true or both are false. |
|
74 |
|
75 new TestCase( SECTION, "true == true", true, true == true ); |
|
76 new TestCase( SECTION, "false == false", true, false == false ); |
|
77 new TestCase( SECTION, "true == false", false, true == false ); |
|
78 new TestCase( SECTION, "false == true", false, false == true ); |
|
79 |
|
80 // return true if x and y refer to the same object. otherwise return false. |
|
81 |
|
82 new TestCase( SECTION, "new MyObject(true) == new MyObject(true)", false, new MyObject(true) == new MyObject(true) ); |
|
83 new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) ); |
|
84 new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) ); |
|
85 |
|
86 |
|
87 new TestCase( SECTION, "x = new MyObject(true); y = x; z = x; z == y", true, eval("x = new MyObject(true); y = x; z = x; z == y") ); |
|
88 new TestCase( SECTION, "x = new MyObject(false); y = x; z = x; z == y", true, eval("x = new MyObject(false); y = x; z = x; z == y") ); |
|
89 new TestCase( SECTION, "x = new Boolean(true); y = x; z = x; z == y", true, eval("x = new Boolean(true); y = x; z = x; z == y") ); |
|
90 new TestCase( SECTION, "x = new Boolean(false); y = x; z = x; z == y", true, eval("x = new Boolean(false); y = x; z = x; z == y") ); |
|
91 |
|
92 new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) ); |
|
93 new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) ); |
|
94 |
|
95 // if x is null and y is undefined, return true. if x is undefined and y is null return true. |
|
96 |
|
97 new TestCase( SECTION, "null == void 0", true, null == void 0 ); |
|
98 new TestCase( SECTION, "void 0 == null", true, void 0 == null ); |
|
99 |
|
100 // if type(x) is Number and type(y) is string, return the result of the comparison x == ToNumber(y). |
|
101 |
|
102 new TestCase( SECTION, "1 == '1'", true, 1 == '1' ); |
|
103 new TestCase( SECTION, "255 == '0xff'", true, 255 == '0xff' ); |
|
104 new TestCase( SECTION, "0 == '\r'", true, 0 == "\r" ); |
|
105 new TestCase( SECTION, "1e19 == '1e19'", true, 1e19 == "1e19" ); |
|
106 |
|
107 |
|
108 new TestCase( SECTION, "new Boolean(true) == true", true, true == new Boolean(true) ); |
|
109 new TestCase( SECTION, "new MyObject(true) == true", true, true == new MyObject(true) ); |
|
110 |
|
111 new TestCase( SECTION, "new Boolean(false) == false", true, new Boolean(false) == false ); |
|
112 new TestCase( SECTION, "new MyObject(false) == false", true, new MyObject(false) == false ); |
|
113 |
|
114 new TestCase( SECTION, "true == new Boolean(true)", true, true == new Boolean(true) ); |
|
115 new TestCase( SECTION, "true == new MyObject(true)", true, true == new MyObject(true) ); |
|
116 |
|
117 new TestCase( SECTION, "false == new Boolean(false)", true, false == new Boolean(false) ); |
|
118 new TestCase( SECTION, "false == new MyObject(false)", true, false == new MyObject(false) ); |
|
119 |
|
120 test(); |
|
121 |
|
122 function MyObject( value ) { |
|
123 this.value = value; |
|
124 this.valueOf = new Function( "return this.value" ); |
|
125 } |