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