js/src/tests/ecma_3/Expressions/11.9.6-1.js

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

mercurial