1/* ***** BEGIN LICENSE BLOCK *****
2* Version: NPL 1.1/GPL 2.0/LGPL 2.1
3*
4* The contents of this file are subject to the Netscape Public License
5* Version 1.1 (the "License"); you may not use this file except in
6* compliance with the License. You may obtain a copy of the License at
7* http://www.mozilla.org/NPL/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is JavaScript Engine testing utilities.
15*
16* The Initial Developer of the Original Code is Netscape Communications Corp.
17* Portions created by the Initial Developer are Copyright (C) 2002
18* the Initial Developer. All Rights Reserved.
19*
20* Contributor(s): pschwartau@netscape.com
21*
22* Alternatively, the contents of this file may be used under the terms of
23* either the GNU General Public License Version 2 or later (the "GPL"), or
24* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25* in which case the provisions of the GPL or the LGPL are applicable instead
26* of those above. If you wish to allow use of your version of this file only
27* under the terms of either the GPL or the LGPL, and not to allow others to
28* use your version of this file under the terms of the NPL, indicate your
29* decision by deleting the provisions above and replace them with the notice
30* and other provisions required by the GPL or the LGPL. If you do not delete
31* the provisions above, a recipient may use your version of this file under
32* the terms of any one of the NPL, the GPL or the LGPL.
33*
34* ***** END LICENSE BLOCK *****
35*
36*
37* Date:    20 Feb 2002
38* SUMMARY: Testing the comparison |undefined === null|
39* See http://bugzilla.mozilla.org/show_bug.cgi?id=126722
40*
41*/
42//-----------------------------------------------------------------------------
43var UBound = 0;
44var bug = 126722;
45var summary = 'Testing the comparison |undefined === null|';
46var status = '';
47var statusitems = [];
48var actual = '';
49var actualvalues = [];
50var expect= '';
51var expectedvalues = [];
52
53
54status = inSection(1);
55if (undefined === null)
56  actual = true;
57else
58  actual = false;
59expect = false;
60addThis();
61
62
63
64status = inSection(2);
65switch(true)
66{
67  case (undefined === null) :
68    actual = true;
69    break;
70
71  default:
72    actual = false;
73}
74expect = false;
75addThis();
76
77
78
79status = inSection(3);
80function f3(x)
81{
82  var res = false;
83
84  switch(true)
85  {
86    case (x === null) :
87      res = true;
88      break;
89
90    default:
91      // do nothing
92  }
93
94  return res;
95}
96
97actual = f3(undefined);
98expect = false;
99addThis();
100
101
102
103status = inSection(4);
104function f4(arr)
105{
106  var elt = '';
107  var res = false;
108
109  for (i=0; i<arr.length; i++)
110  {
111    elt = arr[i];
112
113    switch(true)
114    {
115      case (elt === null) :
116        res = true;
117        break;
118
119      default:
120        // do nothing
121    }
122  }
123
124  return res;
125}
126
127var arr = Array('a', undefined);
128actual = f4(arr);
129expect = false;
130addThis();
131
132
133
134status = inSection(5);
135function f5(arr)
136{
137  var len = arr.length;
138
139  for(var i=0; (arr[i]===undefined) && (i<len); i++)
140    ; //do nothing
141
142  return i;
143}
144
145/*
146 * An array of 5 undefined elements. Note:
147 *
148 * The return value of eval(a STATEMENT) is undefined.
149 * A non-existent PROPERTY is undefined, not a ReferenceError.
150 * No undefined element exists AFTER trailing comma at end.
151 *
152 */
153var arrUndef = [ , undefined, eval('var x = 0'), this.NOT_A_PROPERTY, , ];
154actual = f5(arrUndef);
155expect = 5;
156addThis();
157
158
159
160status = inSection(6);
161function f6(arr)
162{
163  var len = arr.length;
164
165  for(var i=0; (arr[i]===null) && (i<len); i++)
166    ; //do nothing
167
168  return i;
169}
170
171/*
172 * Use same array as above. This time we're comparing to |null|, so we expect 0
173 */
174actual = f6(arrUndef);
175expect = 0;
176addThis();
177
178
179
180
181//-----------------------------------------------------------------------------
182test();
183//-----------------------------------------------------------------------------
184
185
186
187function addThis()
188{
189  statusitems[UBound] = status;
190  actualvalues[UBound] = actual;
191  expectedvalues[UBound] = expect;
192  UBound++;
193}
194
195
196function test()
197{
198  enterFunc('test');
199  printBugNumber(bug);
200  printStatus(summary);
201
202  for (var i=0; i<UBound; i++)
203  {
204    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
205  }
206
207  exitFunc ('test');
208}
209