Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.9.1.js

raw symbols SCIP
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 gTestfile = '11.9.1.js';
7
8 /**
9 File Name: 11.9.1.js
10 ECMA Section: 11.9.1 The equals operator ( == )
11 Description:
12
13 The production EqualityExpression:
14 EqualityExpression == RelationalExpression is evaluated as follows:
15
16 1. Evaluate EqualityExpression.
17 2. Call GetValue(Result(1)).
18 3. Evaluate RelationalExpression.
19 4. Call GetValue(Result(3)).
20 5. Perform the comparison Result(4) == Result(2). (See section 11.9.3)
21 6. Return Result(5).
22 Author: [email protected]
23 Date: 12 november 1997
24 */
25 var SECTION = "11.9.1";
26 var VERSION = "ECMA_1";
27 var BUGNUMBER="77391";
28 startTest();
29
30 writeHeaderToLog( SECTION + " The equals operator ( == )");
31
32 // type x and type y are the same. if type x is undefined or null, return true
33
34 new TestCase( SECTION, "void 0 = void 0", true, void 0 == void 0 );
35 new TestCase( SECTION, "null == null", true, null == null );
36
37 // if x is NaN, return false. if y is NaN, return false.
38
39 new TestCase( SECTION, "NaN == NaN", false, Number.NaN == Number.NaN );
40 new TestCase( SECTION, "NaN == 0", false, Number.NaN == 0 );
41 new TestCase( SECTION, "0 == NaN", false, 0 == Number.NaN );
42 new TestCase( SECTION, "NaN == Infinity", false, Number.NaN == Number.POSITIVE_INFINITY );
43 new TestCase( SECTION, "Infinity == NaN", false, Number.POSITIVE_INFINITY == Number.NaN );
44
45 // if x is the same number value as y, return true.
46
47 new TestCase( SECTION, "Number.MAX_VALUE == Number.MAX_VALUE", true, Number.MAX_VALUE == Number.MAX_VALUE );
48 new TestCase( SECTION, "Number.MIN_VALUE == Number.MIN_VALUE", true, Number.MIN_VALUE == Number.MIN_VALUE );
49 new TestCase( SECTION, "Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY", true, Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY );
50 new TestCase( SECTION, "Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY", true, Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY );
51
52 // if xis 0 and y is -0, return true. if x is -0 and y is 0, return true.
53
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 new TestCase( SECTION, "-0 == -0", true, -0 == -0 );
58
59 // return false.
60
61 new TestCase( SECTION, "0.9 == 1", false, 0.9 == 1 );
62 new TestCase( SECTION, "0.999999 == 1", false, 0.999999 == 1 );
63 new TestCase( SECTION, "0.9999999999 == 1", false, 0.9999999999 == 1 );
64 new TestCase( SECTION, "0.9999999999999 == 1", false, 0.9999999999999 == 1 );
65
66 // type x and type y are the same type, but not numbers.
67
68
69 // x and y are strings. return true if x and y are exactly the same sequence of characters.
70 // otherwise, return false.
71
72 new TestCase( SECTION, "'hello' == 'hello'", true, "hello" == "hello" );
73
74 // x and y are booleans. return true if both are true or both are false.
75
76 new TestCase( SECTION, "true == true", true, true == true );
77 new TestCase( SECTION, "false == false", true, false == false );
78 new TestCase( SECTION, "true == false", false, true == false );
79 new TestCase( SECTION, "false == true", false, false == true );
80
81 // return true if x and y refer to the same object. otherwise return false.
82
83 new TestCase( SECTION, "new MyObject(true) == new MyObject(true)", false, new MyObject(true) == new MyObject(true) );
84 new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) );
85 new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) );
86
87
88 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") );
89 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") );
90 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") );
91 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") );
92
93 new TestCase( SECTION, "new Boolean(true) == new Boolean(true)", false, new Boolean(true) == new Boolean(true) );
94 new TestCase( SECTION, "new Boolean(false) == new Boolean(false)", false, new Boolean(false) == new Boolean(false) );
95
96 // if x is null and y is undefined, return true. if x is undefined and y is null return true.
97
98 new TestCase( SECTION, "null == void 0", true, null == void 0 );
99 new TestCase( SECTION, "void 0 == null", true, void 0 == null );
100
101 // if type(x) is Number and type(y) is string, return the result of the comparison x == ToNumber(y).
102
103 new TestCase( SECTION, "1 == '1'", true, 1 == '1' );
104 new TestCase( SECTION, "255 == '0xff'", true, 255 == '0xff' );
105 new TestCase( SECTION, "0 == '\r'", true, 0 == "\r" );
106 new TestCase( SECTION, "1e19 == '1e19'", true, 1e19 == "1e19" );
107
108
109 new TestCase( SECTION, "new Boolean(true) == true", true, true == new Boolean(true) );
110 new TestCase( SECTION, "new MyObject(true) == true", true, true == new MyObject(true) );
111
112 new TestCase( SECTION, "new Boolean(false) == false", true, new Boolean(false) == false );
113 new TestCase( SECTION, "new MyObject(false) == false", true, new MyObject(false) == false );
114
115 new TestCase( SECTION, "true == new Boolean(true)", true, true == new Boolean(true) );
116 new TestCase( SECTION, "true == new MyObject(true)", true, true == new MyObject(true) );
117
118 new TestCase( SECTION, "false == new Boolean(false)", true, false == new Boolean(false) );
119 new TestCase( SECTION, "false == new MyObject(false)", true, false == new MyObject(false) );
120
121 test();
122
123 function MyObject( value ) {
124 this.value = value;
125 this.valueOf = new Function( "return this.value" );
126 }