d3d10: Implement ID3D10EffectVariable::AsShaderResource().
[wine] / dlls / jscript / tests / lang.js
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 var tmp;
20
21 ok(true, "true is not true?");
22 ok(!false, "!false is not true");
23 ok(!undefined, "!undefined is not true");
24 ok(!null, "!null is not true");
25 ok(!0, "!0 is not true");
26 ok(!0.0, "!0.0 is not true");
27
28 ok(1 === 1, "1 === 1 is false");
29 ok(!(1 === 2), "!(1 === 2) is false");
30 ok(1.0 === 1, "1.0 === 1 is false");
31 ok("abc" === "abc", "\"abc\" === \"abc\" is false");
32 ok(true === true, "true === true is false");
33 ok(null === null, "null === null is false");
34 ok(undefined === undefined, "undefined === undefined is false");
35 ok(!(undefined === null), "!(undefined === null) is false");
36 ok(1E0 === 1, "1E0 === 1 is false");
37 ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38 ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000");
39 ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity");
40
41 ok(1 !== 2, "1 !== 2 is false");
42 ok(null !== undefined, "null !== undefined is false");
43
44 ok(1 == 1, "1 == 1 is false");
45 ok(!(1 == 2), "!(1 == 2) is false");
46 ok(1.0 == 1, "1.0 == 1 is false");
47 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
48 ok(true == true, "true == true is false");
49 ok(null == null, "null == null is false");
50 ok(undefined == undefined, "undefined == undefined is false");
51 ok(undefined == null, "undefined == null is false");
52 ok(true == 1, "true == 1 is false");
53 ok(!(true == 2), "true == 2");
54 ok(0 == false, "0 == false is false");
55
56 ok(1 != 2, "1 != 2 is false");
57 ok(false != 1, "false != 1 is false");
58
59 var trueVar = true;
60 ok(trueVar, "trueVar is not true");
61
62 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
63
64 function testFunc1(x, y) {
65     ok(this !== undefined, "this is undefined");
66     ok(x === true, "x is not true");
67     ok(y === "test", "y is not \"test\"");
68     ok(arguments.length === 2, "arguments.length is not 2");
69     ok(arguments["0"] === true, "arguments[0] is not true");
70     ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
71     ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
72
73     return true;
74 }
75
76 ok(testFunc1.length === 2, "testFunc1.length is not 2");
77
78 ok(Object.prototype !== undefined, "Object.prototype is undefined");
79 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
80 ok(String.prototype !== undefined, "String.prototype is undefined");
81 ok(Array.prototype !== undefined, "Array.prototype is undefined");
82 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
83 ok(Number.prototype !== undefined, "Number.prototype is undefined");
84 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
85 ok(Math !== undefined, "Math is undefined");
86 ok(Math.prototype === undefined, "Math.prototype is not undefined");
87 ok(Function.prototype !== undefined, "Function.prototype is undefined");
88 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
89 ok(Date.prototype !== undefined, "Date.prototype is undefined");
90 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
91
92 Function.prototype.test = true;
93 ok(testFunc1.test === true, "testFunc1.test !== true");
94 ok(Function.test === true, "Function.test !== true");
95
96 ok(typeof(0) === "number", "typeof(0) is not number");
97 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
98 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
99 ok(typeof("") === "string", "typeof(\"\") is not string");
100 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
101 ok(typeof(null) === "object", "typeof(null) is not object");
102 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
103 ok(typeof(Math) === "object", "typeof(Math) is not object");
104 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
105 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
106 ok(typeof(String) === "function", "typeof(String) is not function");
107 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
108 ok(typeof(this) === "object", "typeof(this) is not object");
109
110 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
111
112 var obj1 = new Object();
113 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
114 obj1.test = true;
115 obj1.func = function () {
116     ok(this === obj1, "this is not obj1");
117     ok(this.test === true, "this.test is not true");
118     ok(arguments.length === 1, "arguments.length is not 1");
119     ok(arguments["0"] === true, "arguments[0] is not true");
120     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
121
122     return "test";
123 };
124
125 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
126
127 function testConstr1() {
128     this.var1 = 1;
129
130     ok(this !== undefined, "this is undefined");
131     ok(arguments.length === 1, "arguments.length is not 1");
132     ok(arguments["0"] === true, "arguments[0] is not 1");
133     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
134
135     return false;
136 }
137
138 testConstr1.prototype.pvar = 1;
139
140 var obj2 = new testConstr1(true);
141 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
142 ok(obj2.pvar === 1, "obj2.pvar is not 1");
143
144 testConstr1.prototype.pvar = 2;
145 ok(obj2.pvar === 2, "obj2.pvar is not 2");
146
147 obj2.pvar = 3;
148 testConstr1.prototype.pvar = 1;
149 ok(obj2.pvar === 3, "obj2.pvar is not 3");
150
151 obj1 = new Object();
152 function testConstr3() {
153     return obj1;
154 }
155
156 obj2 = new testConstr3();
157 ok(obj1 === obj2, "obj1 != obj2");
158
159 function testConstr4() {
160     return 2;
161 }
162
163 obj2 = new testConstr3();
164 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
165
166 var obj3 = new Object;
167 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
168
169 for(var iter in "test")
170     ok(false, "unexpected forin call, test = " + iter);
171
172 for(var iter in null)
173     ok(false, "unexpected forin call, test = " + iter);
174
175 for(var iter in false)
176     ok(false, "unexpected forin call, test = " + iter);
177
178 tmp = 0;
179 if(true)
180     tmp = 1;
181 else
182     ok(false, "else evaluated");
183 ok(tmp === 1, "tmp !== 1, if not evaluated?");
184
185 tmp = 0;
186 if(1 === 0)
187     ok(false, "if evaluated");
188 else
189     tmp = 1;
190 ok(tmp === 1, "tmp !== 1, if not evaluated?");
191
192 if(false)
193     ok(false, "if(false) evaluated");
194
195 tmp = 0;
196 if(true)
197     tmp = 1;
198 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
199
200 if(false) {
201 }else {
202 }
203
204 var obj3 = { prop1: 1,  prop2: typeof(false) };
205 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
206 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
207
208 {
209     var blockVar = 1;
210     blockVar = 2;
211 }
212 ok(blockVar === 2, "blockVar !== 2");
213
214 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
215 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
216
217 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
218 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
219 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
220 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
221 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
222 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
223 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
224
225 tmp = 2+2;
226 ok(tmp === 4, "2+2 !== 4");
227 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
228
229 tmp = 2+2.5;
230 ok(tmp === 4.5, "2+2.5 !== 4.5");
231 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
232
233 tmp = 1.5+2.5;
234 ok(tmp === 4, "1.4+2.5 !== 4");
235 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
236
237 tmp = 4-2;
238 ok(tmp === 2, "4-2 !== 2");
239 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
240
241 tmp = 4.5-2;
242 ok(tmp === 2.5, "4.5-2 !== 2.5");
243 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
244
245 tmp = -2;
246 ok(tmp === 0-2, "-2 !== 0-2");
247 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
248
249 tmp = 2*3;
250 ok(tmp === 6, "2*3 !== 6");
251 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
252
253 tmp = 2*3.5;
254 ok(tmp === 7, "2*3.5 !== 7");
255 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
256
257 tmp = 2.5*3.5;
258 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
259 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
260
261 tmp = 4/2;
262 ok(tmp === 2, "4/2 !== 2");
263 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
264
265 tmp = 4.5/1.5;
266 ok(tmp === 3, "4.5/1.5 !== 3");
267 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
268
269 tmp = 3/2;
270 ok(tmp === 1.5, "3/2 !== 1.5");
271 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
272
273 tmp = 3%2;
274 ok(tmp === 1, "3%2 = " + tmp);
275
276 tmp = 4%2;
277 ok(tmp ===0, "4%2 = " + tmp);
278
279 tmp = 3.5%1.5;
280 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
281
282 tmp = 3%true;
283 ok(tmp === 0, "3%true = " + tmp);
284
285 tmp = "ab" + "cd";
286 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
287
288 tmp = 1;
289 ok((tmp += 1) === 2, "tmp += 1 !== 2");
290 ok(tmp === 2, "tmp !== 2");
291
292 tmp = 2;
293 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
294 ok(tmp === 1, "tmp !=== 1");
295
296 tmp = 2;
297 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
298 ok(tmp === 3, "tmp !=== 3");
299
300 tmp = 5;
301 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
302 ok(tmp === 2.5, "tmp !=== 2.5");
303
304 tmp = 3;
305 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
306 ok(tmp === 1, "tmp !== 1");
307
308 tmp = 8;
309 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
310
311 tmp = 8;
312 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
313
314 tmp = 8;
315 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
316
317 tmp = 3 || ok(false, "second or expression called");
318 ok(tmp === 3, "3 || (...) is not 3");
319
320 tmp = false || 2;
321 ok(tmp === 2, "false || 2 is not 2");
322
323 tmp = 0 && ok(false, "second and expression called");
324 ok(tmp === 0, "0 && (...) is not 0");
325
326 tmp = true && "test";
327 ok(tmp === "test", "true && \"test\" is not \"test\"");
328
329 tmp = true && 0;
330 ok(tmp === 0, "true && 0 is not 0");
331
332 tmp = 3 | 4;
333 ok(tmp === 7, "3 | 4 !== 7");
334 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
335
336 tmp = 3.5 | 0;
337 ok(tmp === 3, "3.5 | 0 !== 3");
338 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
339
340 tmp = -3.5 | 0;
341 ok(tmp === -3, "-3.5 | 0 !== -3");
342 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
343
344 tmp = 10;
345 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
346 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
347
348 tmp = 3 & 5;
349 ok(tmp === 1, "3 & 5 !== 1");
350 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
351
352 tmp = 3.5 & 0xffff;
353 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
354 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
355
356 tmp = (-3.5) & 0xffffffff;
357 ok(tmp === -3, "-3.5 & 0xffff !== -3");
358 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
359
360 tmp = 2 << 3;
361 ok(tmp === 16, "2 << 3 = " + tmp);
362
363 tmp = 2 << 35;
364 ok(tmp === 16, "2 << 35 = " + tmp);
365
366 tmp = 8 >> 2;
367 ok(tmp === 2, "8 >> 2 = " + tmp);
368
369 tmp = -64 >> 4;
370 ok(tmp === -4, "-64 >> 4 = " + tmp);
371
372 tmp = 8 >>> 2;
373 ok(tmp === 2, "8 >> 2 = " + tmp);
374
375 tmp = -64 >>> 4;
376 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
377
378 tmp = 10;
379 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
380 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
381
382 tmp = 0xf0f0^0xff00;
383 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
384 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
385
386 tmp = 5;
387 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
388 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
389
390 tmp = ~1;
391 ok(tmp === -2, "~1 !== -2");
392 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
393
394 ok((3,4) === 4, "(3,4) !== 4");
395
396 ok(+3 === 3, "+3 !== 3");
397 ok(+true === 1, "+true !== 1");
398 ok(+false === 0, "+false !== 0");
399 ok(+null === 0, "+null !== 0");
400 ok(+"0" === 0, "+'0' !== 0");
401 ok(+"3" === 3, "+'3' !== 3");
402 ok(+"-3" === -3, "+'-3' !== -3");
403 ok(+"0xff" === 255, "+'0xff' !== 255");
404 ok(+"3e3" === 3000, "+'3e3' !== 3000");
405
406 tmp = new Number(1);
407 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
408 tmp = new String("1");
409 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
410
411 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
412 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
413 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
414 ok("" + null === "null", "\"\" + null !== \"null\"");
415 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
416 ok("" + true === "true", "\"\" + true !== \"true\"");
417 ok("" + false === "false", "\"\" + false !== \"false\"");
418 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
419 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
420
421 ok(1 < 3.4, "1 < 3.4 failed");
422 ok(!(3.4 < 1), "3.4 < 1");
423 ok("abc" < "abcd", "abc < abcd failed");
424 ok("abcd" < "abce", "abce < abce failed");
425 ok("" < "x", "\"\" < \"x\" failed");
426 ok(!(0 < 0), "0 < 0");
427
428 ok(1 <= 3.4, "1 <= 3.4 failed");
429 ok(!(3.4 <= 1), "3.4 <= 1");
430 ok("abc" <= "abcd", "abc <= abcd failed");
431 ok("abcd" <= "abce", "abce <= abce failed");
432 ok("" <= "x", "\"\" <= \"x\" failed");
433 ok(0 <= 0, "0 <= 0 failed");
434
435 ok(3.4 > 1, "3.4 > 1 failed");
436 ok(!(1 > 3.4), "1 > 3.4");
437 ok("abcd" > "abc", "abc > abcd failed");
438 ok("abce" > "abcd", "abce > abce failed");
439 ok("x" > "", "\"x\" > \"\" failed");
440 ok(!(0 > 0), "0 > 0");
441
442 ok(3.4 >= 1, "3.4 >= 1 failed");
443 ok(!(1 >= 3.4), "1 >= 3.4");
444 ok("abcd" >= "abc", "abc >= abcd failed");
445 ok("abce" >= "abcd", "abce >= abce failed");
446 ok("x" >= "", "\"x\" >= \"\" failed");
447 ok(0 >= 0, "0 >= 0");
448
449 tmp = 1;
450 ok(++tmp === 2, "++tmp (1) is not 2");
451 ok(tmp === 2, "incremented tmp is not 2");
452 ok(--tmp === 1, "--tmp (2) is not 1");
453 ok(tmp === 1, "decremented tmp is not 1");
454 ok(tmp++ === 1, "tmp++ (1) is not 1");
455 ok(tmp === 2, "incremented tmp(1) is not 2");
456 ok(tmp-- === 2, "tmp-- (2) is not 2");
457 ok(tmp === 1, "decremented tmp is not 1");
458
459 String.prototype.test = true;
460 ok("".test === true, "\"\".test is not true");
461
462 Boolean.prototype.test = true;
463 ok(true.test === true, "true.test is not true");
464
465 Number.prototype.test = true;
466 ok((0).test === true, "(0).test is not true");
467 ok((0.5).test === true, "(0.5).test is not true");
468
469 var state = "";
470 try {
471     ok(state === "", "try: state = " + state);
472     state = "try";
473 }catch(ex) {
474     ok(false, "unexpected catch");
475 }
476 ok(state === "try", "state = " + state + " expected try");
477
478 state = "";
479 try {
480     ok(state === "", "try: state = " + state);
481     state = "try";
482 }finally {
483     ok(state === "try", "finally: state = " + state);
484     state = "finally";
485 }
486 ok(state === "finally", "state = " + state + " expected finally");
487
488 state = "";
489 try {
490     ok(state === "", "try: state = " + state);
491     state = "try";
492 }catch(ex) {
493     ok(false, "unexpected catch");
494 }finally {
495     ok(state === "try", "finally: state = " + state);
496     state = "finally";
497 }
498 ok(state === "finally", "state = " + state + " expected finally");
499
500 var state = "";
501 try {
502     ok(state === "", "try: state = " + state);
503     state = "try";
504     throw "except";
505 }catch(ex) {
506     ok(state === "try", "catch: state = " + state);
507     ok(ex === "except", "ex is not \"except\"");
508     state = "catch";
509 }
510 ok(state === "catch", "state = " + state + " expected catch");
511
512 var state = "";
513 try {
514     ok(state === "", "try: state = " + state);
515     state = "try";
516     throw true;
517 }catch(ex) {
518     ok(state === "try", "catch: state = " + state);
519     ok(ex === true, "ex is not true");
520     state = "catch";
521 }finally {
522     ok(state === "catch", "finally: state = " + state);
523     state = "finally";
524 }
525 ok(state === "finally", "state = " + state + " expected finally");
526
527 var state = "";
528 try {
529     ok(state === "", "try: state = " + state);
530     state = "try";
531     try { throw true; } finally {}
532 }catch(ex) {
533     ok(state === "try", "catch: state = " + state);
534     ok(ex === true, "ex is not true");
535     state = "catch";
536 }finally {
537     ok(state === "catch", "finally: state = " + state);
538     state = "finally";
539 }
540 ok(state === "finally", "state = " + state + " expected finally");
541
542 var state = "";
543 try {
544     ok(state === "", "try: state = " + state);
545     state = "try";
546     try { throw "except"; } catch(ex) { throw true; }
547 }catch(ex) {
548     ok(state === "try", "catch: state = " + state);
549     ok(ex === true, "ex is not true");
550     state = "catch";
551 }finally {
552     ok(state === "catch", "finally: state = " + state);
553     state = "finally";
554 }
555 ok(state === "finally", "state = " + state + " expected finally");
556
557 function throwFunc(x) {
558     throw x;
559 }
560
561 var state = "";
562 try {
563     ok(state === "", "try: state = " + state);
564     state = "try";
565     throwFunc(true);
566 }catch(ex) {
567     ok(state === "try", "catch: state = " + state);
568     ok(ex === true, "ex is not true");
569     state = "catch";
570 }finally {
571     ok(state === "catch", "finally: state = " + state);
572     state = "finally";
573 }
574 ok(state === "finally", "state = " + state + " expected finally");
575
576 state = "";
577 switch(1) {
578 case "1":
579     ok(false, "unexpected case \"1\"");
580 case 1:
581     ok(state === "", "case 1: state = " + state);
582     state = "1";
583 default:
584     ok(state === "1", "default: state = " + state);
585     state = "default";
586 case false:
587     ok(state === "default", "case false: state = " + state);
588     state = "false";
589 }
590 ok(state === "false", "state = " + state);
591
592 state = "";
593 switch("") {
594 case "1":
595 case 1:
596     ok(false, "unexpected case 1");
597 default:
598     ok(state === "", "default: state = " + state);
599     state = "default";
600 case false:
601     ok(state === "default", "case false: state = " + state);
602     state = "false";
603 }
604 ok(state === "false", "state = " + state);
605
606 state = "";
607 switch(1) {
608 case "1":
609     ok(false, "unexpected case \"1\"");
610 case 1:
611     ok(state === "", "case 1: state = " + state);
612     state = "1";
613 default:
614     ok(state === "1", "default: state = " + state);
615     state = "default";
616     break;
617 case false:
618     ok(false, "unexpected case false");
619 }
620 ok(state === "default", "state = " + state);
621
622 tmp = eval("1");
623 ok(tmp === 1, "eval(\"1\") !== 1");
624 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
625 ok(tmp === 2, "tmp !== 2");
626
627 ok(eval(false) === false, "eval(false) !== false");
628 ok(eval() === undefined, "eval() !== undefined");
629
630 tmp = eval("1", "2");
631 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
632
633 var state = "";
634 try {
635     ok(state === "", "try: state = " + state);
636     state = "try";
637     eval("throwFunc(true);");
638 }catch(ex) {
639     ok(state === "try", "catch: state = " + state);
640     ok(ex === true, "ex is not true");
641     state = "catch";
642 }finally {
643     ok(state === "catch", "finally: state = " + state);
644     state = "finally";
645 }
646 ok(state === "finally", "state = " + state + " expected finally");
647
648 tmp = [,,1,2,,,true];
649 ok(tmp.length === 7, "tmp.length !== 7");
650 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
651 ok(tmp["3"] === 2, "tmp[3] !== 2");
652 ok(tmp["6"] === true, "tmp[6] !== true");
653 ok(tmp[2] === 1, "tmp[2] !== 1");
654
655 ok([1,].length === 2, "[1,].length !== 2");
656 ok([,,].length === 3, "[,,].length !== 3");
657 ok([,].length === 2, "[].length != 2");
658 ok([].length === 0, "[].length != 0");
659
660 tmp = 0;
661 while(tmp < 4) {
662     ok(tmp < 4, "tmp >= 4");
663     tmp++;
664 }
665 ok(tmp === 4, "tmp !== 4");
666
667 tmp = 0;
668 while(true) {
669     ok(tmp < 4, "tmp >= 4");
670     tmp++;
671     if(tmp === 4) {
672         break;
673         ok(false, "break did not break");
674     }
675 }
676 ok(tmp === 4, "tmp !== 4");
677
678 tmp = 0;
679 do {
680     ok(tmp < 4, "tmp >= 4");
681     tmp++;
682 } while(tmp < 4);
683 ok(tmp === 4, "tmp !== 4");
684
685 tmp = 0;
686 do {
687     ok(tmp === 0, "tmp !=== 0");
688     tmp++;
689 } while(false);
690 ok(tmp === 1, "tmp !== 1");
691
692 tmp = 0;
693 do {
694     ok(tmp < 4, "tmp >= 4");
695     tmp++;
696 } while(tmp < 4)
697 ok(tmp === 4, "tmp !== 4")
698
699 tmp = 0;
700 while(tmp < 4) {
701     tmp++;
702     if(tmp === 2) {
703         continue;
704         ok(false, "break did not break");
705     }
706     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
707 }
708 ok(tmp === 4, "tmp !== 4");
709
710 for(tmp=0; tmp < 4; tmp++)
711     ok(tmp < 4, "tmp = " + tmp);
712 ok(tmp === 4, "tmp !== 4");
713
714 for(tmp=0; tmp < 4; tmp++) {
715     if(tmp === 2)
716         break;
717     ok(tmp < 2, "tmp = " + tmp);
718 }
719 ok(tmp === 2, "tmp !== 2");
720
721 for(tmp=0; tmp < 4; tmp++) {
722     if(tmp === 2)
723         continue;
724     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
725 }
726 ok(tmp === 4, "tmp !== 4");
727
728 for(var fi=0; fi < 4; fi++)
729     ok(fi < 4, "fi = " + fi);
730 ok(fi === 4, "fi !== 4");
731
732 ok((void 1) === undefined, "(void 1) !== undefined");
733
734 var inobj = new Object();
735
736 for(var iter in inobj)
737     ok(false, "unexpected iter = " + iter);
738
739 inobj.test = true;
740 tmp = 0;
741 for(iter in inobj) {
742     ok(iter == "test", "unexpected iter = " + iter);
743     tmp++;
744 }
745 ok(tmp === 1, "for..in tmp = " + tmp);
746
747 function forinTestObj() {}
748
749 forinTestObj.prototype.test3 = true;
750
751 var arr = new Array();
752 inobj = new forinTestObj();
753 inobj.test1 = true;
754 inobj.test2 = true;
755
756 tmp = 0;
757 for(iter in inobj) {
758     arr[iter] = true;
759     tmp++;
760 }
761
762 ok(tmp === 3, "for..in tmp = " + tmp);
763 ok(arr["test1"] === true, "arr[test1] !== true");
764 ok(arr["test2"] === true, "arr[test2] !== true");
765 ok(arr["test3"] === true, "arr[test3] !== true");
766
767 tmp = new Object();
768 tmp.test = false;
769 ok((delete tmp.test) === true, "delete returned false");
770 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
771 for(iter in tmp)
772     ok(false, "tmp has prop " + iter);
773
774 tmp.testWith = true;
775 with(tmp)
776     ok(testWith === true, "testWith !== true");
777
778 if(false) {
779     var varTest1 = true;
780 }
781
782 ok(varTest1 === undefined, "varTest1 = " + varTest1);
783 ok(varTest2 === undefined, "varTest2 = " + varTest1);
784
785 var varTest2;
786
787 function varTestFunc(varTest3) {
788     var varTest3;
789
790     ok(varTest3 === 3, "varTest3 = " + varTest3);
791     ok(varTest4 === undefined, "varTest4 = " + varTest4);
792
793     var varTest4;
794 }
795
796 varTestFunc(3);
797
798 deleteTest = 1;
799 delete deleteTest;
800 try {
801     tmp = deleteTest;
802     ok(false, "deleteTest not throwed exception?");
803 }catch(ex) {}
804
805 if (false)
806     if (true)
807         ok(false, "if evaluated");
808     else
809         ok(false, "else should be associated with nearest if statement");
810
811 if (true)
812     if (false)
813         ok(false, "if evaluated");
814     else
815         ok(true, "else should be associated with nearest if statement");
816
817 function instanceOfTest() {}
818 tmp = new instanceOfTest();
819
820 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
821 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
822 ok((tmp instanceof String) === false, "tmp is instance of String");
823
824 instanceOfTest.prototype = new Object();
825 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
826 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
827
828 ok((1 instanceof Object) === false, "1 is instance of Object");
829 ok((false instanceof Boolean) === false, "false is instance of Boolean");
830 ok(("" instanceof Object) === false, "'' is instance of Object");
831
832 (function () {
833     ok((arguments instanceof Object) === true, "argument is not instance of Object");
834     ok((arguments instanceof Array) === false, "argument is not instance of Array");
835     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
836 })(1,2);
837
838 obj = new String();
839 ok(("length" in obj) === true, "length is not in obj");
840 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
841 ok(("abc" in obj) === false, "test is in obj");
842 obj.abc = 1;
843 ok(("abc" in obj) === true, "test is not in obj");
844 ok(("1" in obj) === false, "1 is in obj");
845
846 obj = [1,2,3];
847 ok((1 in obj) === true, "1 is not in obj");
848
849 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
850 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
851 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
852 ok(isNaN() === true, "isNaN() !== true");
853 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
854 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
855 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
856
857 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
858 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
859 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
860 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
861 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
862 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
863 ok(isFinite() === false, "isFinite() !== false");
864
865 ok((1 < NaN) === false, "(1 < NaN) !== false");
866 ok((1 > NaN) === false, "(1 > NaN) !== false");
867 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
868 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
869 ok((NaN < 1) === false, "(NaN < 1) !== false");
870 ok((NaN > 1) === false, "(NaN > 1) !== false");
871 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
872 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
873 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
874 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
875 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
876
877 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
878 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
879 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
880 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
881 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
882 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
883
884 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
885 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
886 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
887 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
888 ok((0 === NaN) === false, "(0 === NaN) !== false");
889
890 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
891 ok((NaN == NaN) === false, "(NaN === NaN) != false");
892 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
893 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
894 ok((0 == NaN) === false, "(0 === NaN) != false");
895
896
897 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
898 tmp = testFunc2(1);
899 ok(tmp === 2, "testFunc2(1) = " + tmp);
900 function testFunc2(x) { return x+1; }
901
902 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
903 tmp = testFunc3(1);
904 ok(tmp === 3, "testFunc3(1) = " + tmp);
905 tmp = function testFunc3(x) { return x+2; };
906
907 tmp = testFunc4(1);
908 ok(tmp === 5, "testFunc4(1) = " + tmp);
909 tmp = function testFunc4(x) { return x+3; };
910 tmp = testFunc4(1);
911 testFunc4 = 1;
912 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
913 ok(tmp === 5, "testFunc4(1) = " + tmp);
914 tmp = function testFunc4(x) { return x+4; };
915 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
916
917 function testEmbededFunctions() {
918     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
919     tmp = testFunc5(1);
920     ok(tmp === 3, "testFunc5(1) = " + tmp);
921     tmp = function testFunc5(x) { return x+2; };
922
923     tmp = testFunc6(1);
924     ok(tmp === 5, "testFunc6(1) = " + tmp);
925     tmp = function testFunc6(x) { return x+3; };
926     tmp = testFunc6(1);
927     ok(tmp === 5, "testFunc6(1) = " + tmp);
928     tmp = function testFunc6(x) { return x+4; };
929     testFunc6 = 1;
930     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
931 }
932
933 testEmbededFunctions();
934
935 date = new Date();
936 date.toString = function() { return "toString"; }
937 ok(""+date === "toString", "''+date = " + date);
938 date.toString = function() { return this; }
939 ok(""+date === ""+date.valueOf(), "''+date = " + date);
940
941 str = new String("test");
942 str.valueOf = function() { return "valueOf"; }
943 ok(""+str === "valueOf", "''+str = " + str);
944 str.valueOf = function() { return new Date(); }
945 ok(""+str === "test", "''+str = " + str);
946
947 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
948
949 var re = /=(\?|%3F)/g;
950 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
951
952 tmp = new Array();
953 for(var i=0; i<2; i++)
954     tmp[i] = /b/;
955 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
956
957 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
958
959 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
960 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
961 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
962 ok(nullDisp !== re, "nullDisp === re");
963 ok(nullDisp === null, "nullDisp === null");
964 ok(nullDisp == null, "nullDisp == null");
965 ok(getVT(true && nullDisp) === "VT_DISPATCH",
966    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
967 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
968 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
969 ok(nullDisp != new Object(), "nullDisp == new Object()");
970 ok(new Object() != nullDisp, "new Object() == nullDisp");
971 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
972 tmp = getVT(Object(nullDisp));
973 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
974 tmp = Object(nullDisp).toString();
975 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
976
977 function do_test() {}
978 function nosemicolon() {} nosemicolon();
979 function () {} nosemicolon();
980
981 if(false) {
982     function in_if_false() { return true; } ok(false, "!?");
983 }
984
985 ok(in_if_false(), "in_if_false failed");
986
987 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
988
989 (function() { newValue = 1; })();
990 ok(newValue === 1, "newValue = " + newValue);
991
992 reportSuccess();