Debian Codegraph @

rhino/testsrc/tests/ecma_3/Expressions/11.9.6-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 /*
7 *
8 * Date: 20 Feb 2002
9 * SUMMARY: Testing the comparison |undefined === null|
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=126722
11 *
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = '11.9.6-1.js';
15 var UBound = 0;
16 var BUGNUMBER = 126722;
17 var summary = 'Testing the comparison |undefined === null|';
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
24
25
26 status = inSection(1);
27 if (undefined === null)
28 actual = true;
29 else
30 actual = false;
31 expect = false;
32 addThis();
33
34
35
36 status = inSection(2);
37 switch(true)
38 {
39 case (undefined === null) :
40 actual = true;
41 break;
42
43 default:
44 actual = false;
45 }
46 expect = false;
47 addThis();
48
49
50
51 status = inSection(3);
52 function f3(x)
53 {
54 var res = false;
55
56 switch(true)
57 {
58 case (x === null) :
59 res = true;
60 break;
61
62 default:
63 // do nothing
64 }
65
66 return res;
67 }
68
69 actual = f3(undefined);
70 expect = false;
71 addThis();
72
73
74
75 status = inSection(4);
76 function f4(arr)
77 {
78 var elt = '';
79 var res = false;
80
81 for (i=0; i<arr.length; i++)
82 {
83 elt = arr[i];
84
85 switch(true)
86 {
87 case (elt === null) :
88 res = true;
89 break;
90
91 default:
92 // do nothing
93 }
94 }
95
96 return res;
97 }
98
99 var arr = Array('a', undefined);
100 actual = f4(arr);
101 expect = false;
102 addThis();
103
104
105
106 status = inSection(5);
107 function f5(arr)
108 {
109 var len = arr.length;
110
111 for(var i=0; (arr[i]===undefined) && (i<len); i++)
112 ; //do nothing
113
114 return i;
115 }
116
117 /*
118 * An array of 5 undefined elements. Note:
119 *
120 * The return value of eval(a STATEMENT) is undefined.
121 * A non-existent PROPERTY is undefined, not a ReferenceError.
122 * No undefined element exists AFTER trailing comma at end.
123 *
124 */
125 var arrUndef = [ , undefined, eval('var x = 0'), this.NOT_A_PROPERTY, , ];
126 actual = f5(arrUndef);
127 expect = 5;
128 addThis();
129
130
131
132 status = inSection(6);
133 function f6(arr)
134 {
135 var len = arr.length;
136
137 for(var i=0; (arr[i]===null) && (i<len); i++)
138 ; //do nothing
139
140 return i;
141 }
142
143 /*
144 * Use same array as above. This time we're comparing to |null|, so we expect 0
145 */
146 actual = f6(arrUndef);
147 expect = 0;
148 addThis();
149
150
151
152
153 //-----------------------------------------------------------------------------
154 test();
155 //-----------------------------------------------------------------------------
156
157
158
159 function addThis()
160 {
161 statusitems[UBound] = status;
162 actualvalues[UBound] = actual;
163 expectedvalues[UBound] = expect;
164 UBound++;
165 }
166
167
168 function test()
169 {
170 enterFunc('test');
171 printBugNumber(BUGNUMBER);
172 printStatus(summary);
173
174 for (var i=0; i<UBound; i++)
175 {
176 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
177 }
178
179 exitFunc ('test');
180 }