Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/forin-001.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 = 'forin-001.js';
7
8 /**
9 * File Name: forin-001.js
10 * ECMA Section:
11 * Description: The forin-001 statement
12 *
13 * Verify that the property name is assigned to the property on the left
14 * hand side of the for...in expression.
15 *
16 * Author: [email protected]
17 * Date: 28 August 1998
18 */
19 var SECTION = "forin-001";
20 var VERSION = "ECMA_2";
21 var TITLE = "The for...in statement";
22 var BUGNUMBER="330890";
23 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
24
25 startTest();
26 writeHeaderToLog( SECTION + " "+ TITLE);
27
28 ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } );
29 ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } );
30 ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } );
31
32 // ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" });
33 // ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" });
34 ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
35
36 test();
37
38 /**
39 * Verify that the left side argument is evaluated with every iteration.
40 * Verify that the name of each property of the object is assigned to a
41 * a property.
42 *
43 */
44 function ForIn_1( object ) {
45 PropertyArray = new Array();
46 ValueArray = new Array();
47
48 for ( PropertyArray[PropertyArray.length] in object ) {
49 ValueArray[ValueArray.length] =
50 object[PropertyArray[PropertyArray.length-1]];
51 }
52
53 for ( var i = 0; i < PropertyArray.length; i++ ) {
54 new TestCase(
55 SECTION,
56 "object[" + PropertyArray[i] +"]",
57 object[PropertyArray[i]],
58 ValueArray[i]
59 );
60 }
61
62 new TestCase(
63 SECTION,
64 "object.length",
65 PropertyArray.length,
66 object.length );
67 }
68
69 /**
70 * Similar to ForIn_1, except it should increment the counter variable
71 * every time the left hand expression is evaluated.
72 */
73 function ForIn_2( object ) {
74 PropertyArray = new Array();
75 ValueArray = new Array();
76 var i = 0;
77
78 for ( PropertyArray[i++] in object ) {
79 ValueArray[ValueArray.length] =
80 object[PropertyArray[PropertyArray.length-1]];
81 }
82
83 for ( i = 0; i < PropertyArray.length; i++ ) {
84 new TestCase(
85 SECTION,
86 "object[" + PropertyArray[i] +"]",
87 object[PropertyArray[i]],
88 ValueArray[i]
89 );
90 }
91
92 new TestCase(
93 SECTION,
94 "object.length",
95 PropertyArray.length,
96 object.length );
97 }
98
99 /**
100 * Break out of a for...in loop
101 *
102 *
103 */
104 function ForIn_3( object ) {
105 var checkBreak = "pass";
106 var properties = new Array();
107 var values = new Array();
108
109 for ( properties[properties.length] in object ) {
110 values[values.length] = object[properties[properties.length-1]];
111 break;
112 checkBreak = "fail";
113 }
114
115 new TestCase(
116 SECTION,
117 "check break out of for...in",
118 "pass",
119 checkBreak );
120
121 new TestCase(
122 SECTION,
123 "properties.length",
124 1,
125 properties.length );
126
127 new TestCase(
128 SECTION,
129 "object["+properties[0]+"]",
130 values[0],
131 object[properties[0]] );
132 }
133
134 /**
135 * Break out of a labeled for...in loop.
136 */
137 function ForIn_4( object ) {
138 var result1 = 0;
139 var result2 = 0;
140 var result3 = 0;
141 var result4 = 0;
142 var i = 0;
143 var property = new Array();
144
145 butterbean: {
146 result1++;
147
148 for ( property[i++] in object ) {
149 result2++;
150 break;
151 result4++;
152 }
153 result3++;
154 }
155
156 new TestCase(
157 SECTION,
158 "verify labeled statement is only executed once",
159 true,
160 result1 == 1 );
161
162 new TestCase(
163 SECTION,
164 "verify statements in for loop are evaluated",
165 true,
166 result2 == i );
167
168 new TestCase(
169 SECTION,
170 "verify break out of labeled for...in loop",
171 true,
172 result4 == 0 );
173
174 new TestCase(
175 SECTION,
176 "verify break out of labeled block",
177 true,
178 result3 == 0 );
179 }
180
181 /**
182 * Labeled break out of a labeled for...in loop.
183 */
184 function ForIn_5 (object) {
185 var result1 = 0;
186 var result2 = 0;
187 var result3 = 0;
188 var result4 = 0;
189 var i = 0;
190 var property = new Array();
191
192 bigredbird: {
193 result1++;
194 for ( property[i++] in object ) {
195 result2++;
196 break bigredbird;
197 result4++;
198 }
199 result3++;
200 }
201
202 new TestCase(
203 SECTION,
204 "verify labeled statement is only executed once",
205 true,
206 result1 == 1 );
207
208 new TestCase(
209 SECTION,
210 "verify statements in for loop are evaluated",
211 true,
212 result2 == i );
213
214 new TestCase(
215 SECTION,
216 "verify break out of labeled for...in loop",
217 true,
218 result4 == 0 );
219
220 new TestCase(
221 SECTION,
222 "verify break out of labeled block",
223 true,
224 result3 == 0 );
225 }
226
227 /**
228 * Labeled continue from a labeled for...in loop
229 */
230 function ForIn_7( object ) {
231 var result1 = 0;
232 var result2 = 0;
233 var result3 = 0;
234 var result4 = 0;
235 var i = 0;
236 var property = new Array();
237
238 bigredbird:
239 for ( property[i++] in object ) {
240 result2++;
241 continue bigredbird;
242 result4++;
243 }
244
245 new TestCase(
246 SECTION,
247 "verify statements in for loop are evaluated",
248 true,
249 result2 == i );
250
251 new TestCase(
252 SECTION,
253 "verify break out of labeled for...in loop",
254 true,
255 result4 == 0 );
256
257 new TestCase(
258 SECTION,
259 "verify break out of labeled block",
260 true,
261 result3 == 1 );
262 }
263
264
265 /**
266 * continue in a for...in loop
267 *
268 */
269 function ForIn_8( object ) {
270 var checkBreak = "pass";
271 var properties = new Array();
272 var values = new Array();
273
274 for ( properties[properties.length] in object ) {
275 values[values.length] = object[properties[properties.length-1]];
276 break;
277 checkBreak = "fail";
278 }
279
280 new TestCase(
281 SECTION,
282 "check break out of for...in",
283 "pass",
284 checkBreak );
285
286 new TestCase(
287 SECTION,
288 "properties.length",
289 1,
290 properties.length );
291
292 new TestCase(
293 SECTION,
294 "object["+properties[0]+"]",
295 values[0],
296 object[properties[0]] );
297 }
298