2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
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");
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");
37 ok(1 !== 2, "1 !== 2 is false");
38 ok(null !== undefined, "null !== undefined is false");
40 ok(1 == 1, "1 == 1 is false");
41 ok(!(1 == 2), "!(1 == 2) is false");
42 ok(1.0 == 1, "1.0 == 1 is false");
43 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
44 ok(true == true, "true == true is false");
45 ok(null == null, "null == null is false");
46 ok(undefined == undefined, "undefined == undefined is false");
47 ok(undefined == null, "undefined == null is false");
48 ok(true == 1, "true == 1 is false");
49 ok(!(true == 2), "true == 2");
50 ok(0 == false, "0 == false is false");
52 ok(1 != 2, "1 != 2 is false");
53 ok(false != 1, "false != 1 is false");
56 ok(trueVar, "trueVar is not true");
58 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
60 function testFunc1(x, y) {
61 ok(this !== undefined, "this is undefined");
62 ok(x === true, "x is not 1");
63 ok(y === "test", "y is not \"test\"");
64 ok(arguments.length === 2, "arguments.length is not 2");
65 ok(arguments["0"] === true, "arguments[0] is not true");
66 ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
71 ok(testFunc1.length === 2, "testFunc1.length is not 2");
73 ok(Object.prototype !== undefined, "Object.prototype is undefined");
74 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
75 ok(String.prototype !== undefined, "String.prototype is undefined");
76 ok(Array.prototype !== undefined, "Array.prototype is undefined");
77 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
78 ok(Number.prototype !== undefined, "Number.prototype is undefined");
79 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
80 ok(Math !== undefined, "Math is undefined");
81 ok(Math.prototype === undefined, "Math.prototype is not undefined");
82 ok(Function.prototype !== undefined, "Function.prototype is undefined");
83 ok(Function.prototype.prototype === undefined, "Function.prototype is not undefined");
84 ok(Date.prototype !== undefined, "Date.prototype is undefined");
85 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
87 Function.prototype.test = true;
88 ok(testFunc1.test === true, "testFunc1.test !== true");
89 ok(Function.test === true, "Function.test !== true");
91 ok(typeof(0) === "number", "typeof(0) is not number");
92 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
93 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
94 ok(typeof("") === "string", "typeof(\"\") is not string");
95 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
96 ok(typeof(null) === "object", "typeof(null) is not object");
97 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
98 ok(typeof(Math) === "object", "typeof(Math) is not object");
99 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
100 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
101 ok(typeof(String) === "function", "typeof(String) is not function");
102 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
103 ok(typeof(this) === "object", "typeof(this) is not object");
105 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
107 var obj1 = new Object();
108 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
110 obj1.func = function () {
111 ok(this === obj1, "this is not obj1");
112 ok(this.test === true, "this.test is not true");
113 ok(arguments.length === 1, "arguments.length is not 1");
114 ok(arguments["0"] === true, "arguments[0] is not true");
119 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
121 function testConstr1() {
124 ok(this !== undefined, "this is undefined");
125 ok(arguments.length === 1, "arguments.length is not 1");
126 ok(arguments["0"] === true, "arguments[0] is not 1");
131 testConstr1.prototype.pvar = 1;
133 var obj2 = new testConstr1(true);
134 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
135 ok(obj2.pvar === 1, "obj2.pvar is not 1");
137 testConstr1.prototype.pvar = 2;
138 ok(obj2.pvar === 2, "obj2.pvar is not 2");
141 testConstr1.prototype.pvar = 1;
142 ok(obj2.pvar === 3, "obj2.pvar is not 3");
144 var obj3 = new Object;
145 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
147 for(var iter in "test")
148 ok(false, "unexpected forin call, test = " + iter);
150 for(var iter in null)
151 ok(false, "unexpected forin call, test = " + iter);
153 for(var iter in false)
154 ok(false, "unexpected forin call, test = " + iter);
160 ok(false, "else evaluated");
161 ok(tmp === 1, "tmp !== 1, if not evaluated?");
165 ok(false, "if evaluated");
168 ok(tmp === 1, "tmp !== 1, if not evaluated?");
171 ok(false, "if(false) evaluated");
176 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
182 var obj3 = { prop1: 1, prop2: typeof(false) };
183 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
184 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
190 ok(blockVar === 2, "blockVar !== 2");
192 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
193 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
195 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
196 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
197 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
198 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
199 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
200 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
201 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
204 ok(tmp === 4, "2+2 !== 4");
205 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
208 ok(tmp === 4.5, "2+2.5 !== 4.5");
209 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
212 ok(tmp === 4, "1.4+2.5 !== 4");
213 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
216 ok(tmp === 2, "4-2 !== 2");
217 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
220 ok(tmp === 2.5, "4.5-2 !== 2.5");
221 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
224 ok(tmp === 0-2, "-2 !== 0-2");
225 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
228 ok(tmp === 6, "2*3 !== 6");
229 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
232 ok(tmp === 7, "2*3.5 !== 7");
233 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
236 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
237 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
240 ok(tmp === 2, "4/2 !== 2");
241 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
244 ok(tmp === 3, "4.5/1.5 !== 3");
245 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
248 ok(tmp === 1.5, "3/2 !== 1.5");
249 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
252 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
255 ok((tmp += 1) === 2, "tmp += 1 !== 2");
256 ok(tmp === 2, "tmp !== 2");
259 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
260 ok(tmp === 1, "tmp !=== 1");
263 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
264 ok(tmp === 3, "tmp !=== 3");
267 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
268 ok(tmp === 2.5, "tmp !=== 2.5");
271 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
274 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
277 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
279 tmp = 3 || ok(false, "second or expression called");
280 ok(tmp === 3, "3 || (...) is not 3");
283 ok(tmp === 2, "false || 2 is not 2");
285 tmp = 0 && ok(false, "second and expression called");
286 ok(tmp === 0, "0 && (...) is not 0");
288 tmp = true && "test";
289 ok(tmp === "test", "true && \"test\" is not \"test\"");
292 ok(tmp === 0, "true && 0 is not 0");
295 ok(tmp === 7, "3 | 4 !== 7");
296 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
299 ok(tmp === 3, "3.5 | 0 !== 3");
300 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
303 ok(tmp === -3, "-3.5 | 0 !== -3");
304 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
307 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
308 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
311 ok(tmp === 1, "3 & 5 !== 1");
312 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
315 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
316 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
318 tmp = (-3.5) & 0xffffffff;
319 ok(tmp === -3, "-3.5 & 0xffff !== -3");
320 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
323 ok(tmp === 16, "2 << 3 = " + tmp);
326 ok(tmp === 16, "2 << 35 = " + tmp);
329 ok(tmp === 2, "8 >> 2 = " + tmp);
332 ok(tmp === -4, "-64 >> 4 = " + tmp);
335 ok(tmp === 2, "8 >> 2 = " + tmp);
338 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
341 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
342 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
345 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
346 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
349 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
350 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
353 ok(tmp === -2, "~1 !== -2");
354 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
356 ok((3,4) === 4, "(3,4) !== 4");
358 ok(+3 === 3, "+3 !== 3");
359 ok(+true === 1, "+true !== 1");
360 ok(+false === 0, "+false !== 0");
361 ok(+null === 0, "+null !== 0");
362 ok(+"0" === 0, "+'0' !== 0");
363 ok(+"3" === 3, "+'3' !== 3");
364 ok(+"-3" === -3, "+'-3' !== -3");
365 ok(+"0xff" === 255, "+'0xff' !== 255");
366 ok(+"3e3" === 3000, "+'3e3' !== 3000");
369 ok(+tmp === 1, "ToNumber(new Number(1)) = " + (+tmp));
370 tmp = new String("1");
371 ok(+tmp === 1, "ToNumber(new String('1')) = " + (+tmp));
373 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
374 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
375 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
376 ok("" + null === "null", "\"\" + null !== \"null\"");
377 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
378 ok("" + true === "true", "\"\" + true !== \"true\"");
379 ok("" + false === "false", "\"\" + false !== \"false\"");
380 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
381 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
383 ok(1 < 3.4, "1 < 3.4 failed");
384 ok(!(3.4 < 1), "3.4 < 1");
385 ok("abc" < "abcd", "abc < abcd failed");
386 ok("abcd" < "abce", "abce < abce failed");
387 ok("" < "x", "\"\" < \"x\" failed");
388 ok(!(0 < 0), "0 < 0");
390 ok(1 <= 3.4, "1 <= 3.4 failed");
391 ok(!(3.4 <= 1), "3.4 <= 1");
392 ok("abc" <= "abcd", "abc <= abcd failed");
393 ok("abcd" <= "abce", "abce <= abce failed");
394 ok("" <= "x", "\"\" <= \"x\" failed");
395 ok(0 <= 0, "0 <= 0 failed");
397 ok(3.4 > 1, "3.4 > 1 failed");
398 ok(!(1 > 3.4), "1 > 3.4");
399 ok("abcd" > "abc", "abc > abcd failed");
400 ok("abce" > "abcd", "abce > abce failed");
401 ok("x" > "", "\"x\" > \"\" failed");
402 ok(!(0 > 0), "0 > 0");
404 ok(3.4 >= 1, "3.4 >= 1 failed");
405 ok(!(1 >= 3.4), "1 >= 3.4");
406 ok("abcd" >= "abc", "abc >= abcd failed");
407 ok("abce" >= "abcd", "abce >= abce failed");
408 ok("x" >= "", "\"x\" >= \"\" failed");
409 ok(0 >= 0, "0 >= 0");
412 ok(++tmp === 2, "++tmp (1) is not 2");
413 ok(tmp === 2, "incremented tmp is not 2");
414 ok(--tmp === 1, "--tmp (2) is not 1");
415 ok(tmp === 1, "decremented tmp is not 1");
416 ok(tmp++ === 1, "tmp++ (1) is not 1");
417 ok(tmp === 2, "incremented tmp(1) is not 2");
418 ok(tmp-- === 2, "tmp-- (2) is not 2");
419 ok(tmp === 1, "decremented tmp is not 1");
421 String.prototype.test = true;
422 ok("".test === true, "\"\".test is not true");
424 Boolean.prototype.test = true;
425 ok(true.test === true, "true.test is not true");
427 Number.prototype.test = true;
428 ok((0).test === true, "(0).test is not true");
429 ok((0.5).test === true, "(0.5).test is not true");
433 ok(state === "", "try: state = " + state);
436 ok(false, "unexpected catch");
438 ok(state === "try", "state = " + state + " expected try");
442 ok(state === "", "try: state = " + state);
445 ok(state === "try", "funally: state = " + state);
448 ok(state === "finally", "state = " + state + " expected finally");
452 ok(state === "", "try: state = " + state);
455 ok(false, "unexpected catch");
457 ok(state === "try", "funally: state = " + state);
460 ok(state === "finally", "state = " + state + " expected finally");
464 ok(state === "", "try: state = " + state);
468 ok(state === "try", "catch: state = " + state);
469 ok(ex === "except", "ex is not \"except\"");
472 ok(state === "catch", "state = " + state + " expected catch");
476 ok(state === "", "try: state = " + state);
480 ok(state === "try", "catch: state = " + state);
481 ok(ex === true, "ex is not true");
484 ok(state === "catch", "funally: state = " + state);
487 ok(state === "finally", "state = " + state + " expected finally");
491 ok(state === "", "try: state = " + state);
493 try { throw true; } finally {}
495 ok(state === "try", "catch: state = " + state);
496 ok(ex === true, "ex is not true");
499 ok(state === "catch", "funally: state = " + state);
502 ok(state === "finally", "state = " + state + " expected finally");
506 ok(state === "", "try: state = " + state);
508 try { throw "except"; } catch(ex) { throw true; }
510 ok(state === "try", "catch: state = " + state);
511 ok(ex === true, "ex is not true");
514 ok(state === "catch", "funally: state = " + state);
517 ok(state === "finally", "state = " + state + " expected finally");
519 function throwFunc(x) {
525 ok(state === "", "try: state = " + state);
529 ok(state === "try", "catch: state = " + state);
530 ok(ex === true, "ex is not true");
533 ok(state === "catch", "funally: state = " + state);
536 ok(state === "finally", "state = " + state + " expected finally");
541 ok(false, "unexpected case \"1\"");
543 ok(state === "", "case 1: state = " + state);
546 ok(state === "1", "default: state = " + state);
549 ok(state === "default", "case false: state = " + state);
552 ok(state === "false", "state = " + state);
558 ok(false, "unexpected case 1");
560 ok(state === "", "default: state = " + state);
563 ok(state === "default", "case false: state = " + state);
566 ok(state === "false", "state = " + state);
571 ok(false, "unexpected case \"1\"");
573 ok(state === "", "case 1: state = " + state);
576 ok(state === "1", "default: state = " + state);
580 ok(false, "unexpected case false");
582 ok(state === "default", "state = " + state);
585 ok(tmp === 1, "eval(\"1\") !== 1");
586 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
587 ok(tmp === 2, "tmp !== 2");
589 ok(eval(false) === false, "eval(false) !== false");
590 ok(eval() === undefined, "eval() !== undefined");
592 tmp = eval("1", "2");
593 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
597 ok(state === "", "try: state = " + state);
599 eval("throwFunc(true);");
601 ok(state === "try", "catch: state = " + state);
602 ok(ex === true, "ex is not true");
605 ok(state === "catch", "funally: state = " + state);
608 ok(state === "finally", "state = " + state + " expected finally");
610 tmp = [,,1,2,,,true];
611 ok(tmp.length === 7, "tmp.length !== 7");
612 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
613 ok(tmp["3"] === 2, "tmp[3] !== 2");
614 ok(tmp["6"] === true, "tmp[6] !== true");
615 ok(tmp[2] === 1, "tmp[2] !== 1");
617 ok([1,].length === 2, "[1,].length !== 2");
618 ok([,,].length === 3, "[,,].length !== 3");
619 ok([,].length === 2, "[].length != 2");
620 ok([].length === 0, "[].length != 0");
624 ok(tmp < 4, "tmp >= 4");
627 ok(tmp === 4, "tmp !== 4");
631 ok(tmp < 4, "tmp >= 4");
635 ok(false, "break did not break");
638 ok(tmp === 4, "tmp !== 4");
642 ok(tmp < 4, "tmp >= 4");
645 ok(tmp === 4, "tmp !== 4");
649 ok(tmp === 0, "tmp !=== 0");
652 ok(tmp === 1, "tmp !== 1");
659 ok(false, "break did not break");
661 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
663 ok(tmp === 4, "tmp !== 4");
665 for(tmp=0; tmp < 4; tmp++)
666 ok(tmp < 4, "tmp = " + tmp);
667 ok(tmp === 4, "tmp !== 4");
669 for(tmp=0; tmp < 4; tmp++) {
672 ok(tmp < 2, "tmp = " + tmp);
674 ok(tmp === 2, "tmp !== 2");
676 for(tmp=0; tmp < 4; tmp++) {
679 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
681 ok(tmp === 4, "tmp !== 4");
683 for(var fi=0; fi < 4; fi++)
684 ok(fi < 4, "fi = " + fi);
685 ok(fi === 4, "fi !== 4");
687 ok((void 1) === undefined, "(void 1) !== undefined");
689 var inobj = new Object();
691 for(var iter in inobj)
692 ok(false, "unexpected iter = " + iter);
697 ok(iter == "test", "unexpected iter = " + iter);
700 ok(tmp === 1, "for..in tmp = " + tmp);
702 function forinTestObj() {}
704 forinTestObj.prototype.test3 = true;
706 var arr = new Array();
707 inobj = new forinTestObj();
717 ok(tmp === 3, "for..in tmp = " + tmp);
718 ok(arr["test1"] === true, "arr[test1] !== true");
719 ok(arr["test2"] === true, "arr[test2] !== true");
720 ok(arr["test3"] === true, "arr[test3] !== true");
724 ok((delete tmp.test) === true, "delete returned false");
725 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
727 ok(false, "tmp has prop " + iter);
731 ok(testWith === true, "testWith !== true");
737 ok(varTest1 === undefined, "varTest1 = " + varTest1);
738 ok(varTest2 === undefined, "varTest2 = " + varTest1);
742 function varTestFunc(varTest3) {
745 ok(varTest3 === 3, "varTest3 = " + varTest3);
746 ok(varTest4 === undefined, "varTest4 = " + varTest4);
757 ok(false, "deleteTest not throwed exception?");