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");
83 ok(typeof(0) === "number", "typeof(0) is not number");
84 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
85 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
86 ok(typeof("") === "string", "typeof(\"\") is not string");
87 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
88 ok(typeof(null) === "object", "typeof(null) is not object");
89 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
90 ok(typeof(Math) === "object", "typeof(Math) is not object");
91 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
92 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
93 ok(typeof(String) === "function", "typeof(String) is not function");
94 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
95 ok(typeof(this) === "object", "typeof(this) is not object");
97 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
99 var obj1 = new Object();
100 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
102 obj1.func = function () {
103 ok(this === obj1, "this is not obj1");
104 ok(this.test === true, "this.test is not true");
105 ok(arguments.length === 1, "arguments.length is not 1");
106 ok(arguments["0"] === true, "arguments[0] is not true");
111 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
113 function testConstr1() {
116 ok(this !== undefined, "this is undefined");
117 ok(arguments.length === 1, "arguments.length is not 1");
118 ok(arguments["0"] === true, "arguments[0] is not 1");
123 testConstr1.prototype.pvar = 1;
125 var obj2 = new testConstr1(true);
126 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
127 ok(obj2.pvar === 1, "obj2.pvar is not 1");
129 testConstr1.prototype.pvar = 2;
130 ok(obj2.pvar === 2, "obj2.pvar is not 2");
133 testConstr1.prototype.pvar = 1;
134 ok(obj2.pvar === 3, "obj2.pvar is not 3");
136 var obj3 = new Object;
137 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
143 ok(false, "else evaluated");
144 ok(tmp === 1, "tmp !== 1, if not evaluated?");
148 ok(false, "if evaluated");
151 ok(tmp === 1, "tmp !== 1, if not evaluated?");
154 ok(false, "if(false) evaluated");
159 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
161 var obj3 = { prop1: 1, prop2: typeof(false) };
162 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
163 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
169 ok(blockVar === 2, "blockVar !== 2");
171 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
172 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
174 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
175 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
176 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
177 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
178 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
179 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
180 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
183 ok(tmp === 4, "2+2 !== 4");
184 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
187 ok(tmp === 4.5, "2+2.5 !== 4.5");
188 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
191 ok(tmp === 4, "1.4+2.5 !== 4");
192 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
195 ok(tmp === 2, "4-2 !== 2");
196 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
199 ok(tmp === 2.5, "4.5-2 !== 2.5");
200 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
203 ok(tmp === 0-2, "-2 !== 0-2");
204 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
207 ok(tmp === 6, "2*3 !== 6");
208 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
211 ok(tmp === 7, "2*3.5 !== 7");
212 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
215 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
216 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
219 ok(tmp === 2, "4/2 !== 2");
220 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
223 ok(tmp === 3, "4.5/1.5 !== 3");
224 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
227 ok(tmp === 1.5, "3/2 !== 1.5");
228 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
231 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
234 ok((tmp += 1) === 2, "tmp += 1 !== 2");
235 ok(tmp === 2, "tmp !== 2");
238 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
239 ok(tmp === 1, "tmp !=== 1");
242 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
243 ok(tmp === 3, "tmp !=== 3");
246 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
247 ok(tmp === 2.5, "tmp !=== 2.5");
250 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
253 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
255 tmp = 3 || ok(false, "second or expression called");
256 ok(tmp === 3, "3 || (...) is not 3");
259 ok(tmp === 2, "false || 2 is not 2");
261 tmp = 0 && ok(false, "second and expression called");
262 ok(tmp === 0, "0 && (...) is not 0");
264 tmp = true && "test";
265 ok(tmp === "test", "true && \"test\" is not \"test\"");
268 ok(tmp === 0, "true && 0 is not 0");
271 ok(tmp === 7, "3 | 4 !== 7");
272 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
275 ok(tmp === 3, "3.5 | 0 !== 3");
276 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
279 ok(tmp === -3, "-3.5 | 0 !== -3");
280 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
283 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
284 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
287 ok(tmp === 1, "3 & 5 !== 1");
288 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
291 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
292 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
294 tmp = (-3.5) & 0xffffffff;
295 ok(tmp === -3, "-3.5 & 0xffff !== -3");
296 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
299 ok(tmp === 16, "2 << 3 = " + tmp);
302 ok(tmp === 16, "2 << 35 = " + tmp);
305 ok(tmp === 2, "8 >> 2 = " + tmp);
308 ok(tmp === -4, "-64 >> 4 = " + tmp);
311 ok(tmp === 2, "8 >> 2 = " + tmp);
314 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
317 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
318 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
321 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
322 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
325 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
326 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
329 ok(tmp === -2, "~1 !== -2");
330 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
332 ok((3,4) === 4, "(3,4) !== 4");
334 ok(+3 === 3, "+3 !== 3");
335 ok(+true === 1, "+true !== 1");
336 ok(+false === 0, "+false !== 0");
337 ok(+null === 0, "+null !== 0");
339 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
340 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
341 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
343 ok(1 < 3.4, "1 < 3.4 failed");
344 ok(!(3.4 < 1), "3.4 < 1");
345 ok("abc" < "abcd", "abc < abcd failed");
346 ok("abcd" < "abce", "abce < abce failed");
347 ok("" < "x", "\"\" < \"x\" failed");
348 ok(!(0 < 0), "0 < 0");
350 ok(1 <= 3.4, "1 <= 3.4 failed");
351 ok(!(3.4 <= 1), "3.4 <= 1");
352 ok("abc" <= "abcd", "abc <= abcd failed");
353 ok("abcd" <= "abce", "abce <= abce failed");
354 ok("" <= "x", "\"\" <= \"x\" failed");
355 ok(0 <= 0, "0 <= 0 failed");
357 ok(3.4 > 1, "3.4 > 1 failed");
358 ok(!(1 > 3.4), "1 > 3.4");
359 ok("abcd" > "abc", "abc > abcd failed");
360 ok("abce" > "abcd", "abce > abce failed");
361 ok("x" > "", "\"x\" > \"\" failed");
362 ok(!(0 > 0), "0 > 0");
364 ok(3.4 >= 1, "3.4 >= 1 failed");
365 ok(!(1 >= 3.4), "1 >= 3.4");
366 ok("abcd" >= "abc", "abc >= abcd failed");
367 ok("abce" >= "abcd", "abce >= abce failed");
368 ok("x" >= "", "\"x\" >= \"\" failed");
369 ok(0 >= 0, "0 >= 0");
372 ok(++tmp === 2, "++tmp (1) is not 2");
373 ok(tmp === 2, "incremented tmp is not 2");
374 ok(--tmp === 1, "--tmp (2) is not 1");
375 ok(tmp === 1, "decremented tmp is not 1");
376 ok(tmp++ === 1, "tmp++ (1) is not 1");
377 ok(tmp === 2, "incremented tmp(1) is not 2");
378 ok(tmp-- === 2, "tmp-- (2) is not 2");
379 ok(tmp === 1, "decremented tmp is not 1");
381 String.prototype.test = true;
382 ok("".test === true, "\"\".test is not true");
384 Boolean.prototype.test = true;
385 ok(true.test === true, "true.test is not true");
387 Number.prototype.test = true;
388 ok((0).test === true, "(0).test is not true");
389 ok((0.5).test === true, "(0.5).test is not true");
393 ok(state === "", "try: state = " + state);
396 ok(false, "unexpected catch");
398 ok(state === "try", "state = " + state + " expected try");
402 ok(state === "", "try: state = " + state);
405 ok(state === "try", "funally: state = " + state);
408 ok(state === "finally", "state = " + state + " expected finally");
412 ok(state === "", "try: state = " + state);
415 ok(false, "unexpected catch");
417 ok(state === "try", "funally: state = " + state);
420 ok(state === "finally", "state = " + state + " expected finally");
424 ok(state === "", "try: state = " + state);
428 ok(state === "try", "catch: state = " + state);
429 ok(ex === "except", "ex is not \"except\"");
432 ok(state === "catch", "state = " + state + " expected catch");
436 ok(state === "", "try: state = " + state);
440 ok(state === "try", "catch: state = " + state);
441 ok(ex === true, "ex is not true");
444 ok(state === "catch", "funally: state = " + state);
447 ok(state === "finally", "state = " + state + " expected finally");
451 ok(state === "", "try: state = " + state);
453 try { throw true; } finally {}
455 ok(state === "try", "catch: state = " + state);
456 ok(ex === true, "ex is not true");
459 ok(state === "catch", "funally: state = " + state);
462 ok(state === "finally", "state = " + state + " expected finally");
466 ok(state === "", "try: state = " + state);
468 try { throw "except"; } catch(ex) { throw true; }
470 ok(state === "try", "catch: state = " + state);
471 ok(ex === true, "ex is not true");
474 ok(state === "catch", "funally: state = " + state);
477 ok(state === "finally", "state = " + state + " expected finally");
479 function throwFunc(x) {
485 ok(state === "", "try: state = " + state);
489 ok(state === "try", "catch: state = " + state);
490 ok(ex === true, "ex is not true");
493 ok(state === "catch", "funally: state = " + state);
496 ok(state === "finally", "state = " + state + " expected finally");
501 ok(false, "unexpected case \"1\"");
503 ok(state === "", "case 1: state = " + state);
506 ok(state === "1", "default: state = " + state);
509 ok(state === "default", "case false: state = " + state);
512 ok(state === "false", "state = " + state);
518 ok(false, "unexpected case 1");
520 ok(state === "", "default: state = " + state);
523 ok(state === "default", "case false: state = " + state);
526 ok(state === "false", "state = " + state);
531 ok(false, "unexpected case \"1\"");
533 ok(state === "", "case 1: state = " + state);
536 ok(state === "1", "default: state = " + state);
540 ok(false, "unexpected case false");
542 ok(state === "default", "state = " + state);
545 ok(tmp === 1, "eval(\"1\") !== 1");
546 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
547 ok(tmp === 2, "tmp !== 2");
549 ok(eval(false) === false, "eval(false) !== false");
550 ok(eval() === undefined, "eval() !== undefined");
552 tmp = eval("1", "2");
553 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
557 ok(state === "", "try: state = " + state);
559 eval("throwFunc(true);");
561 ok(state === "try", "catch: state = " + state);
562 ok(ex === true, "ex is not true");
565 ok(state === "catch", "funally: state = " + state);
568 ok(state === "finally", "state = " + state + " expected finally");
570 tmp = [,,1,2,,,true];
571 ok(tmp.length === 7, "tmp.length !== 7");
572 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
573 ok(tmp["3"] === 2, "tmp[3] !== 2");
574 ok(tmp["6"] === true, "tmp[6] !== true");
575 ok(tmp[2] === 1, "tmp[2] !== 1");
579 ok(tmp < 4, "tmp >= 4");
582 ok(tmp === 4, "tmp !== 4");
586 ok(tmp < 4, "tmp >= 4");
590 ok(false, "break did not break");
593 ok(tmp === 4, "tmp !== 4");
597 ok(tmp < 4, "tmp >= 4");
600 ok(tmp === 4, "tmp !== 4");
604 ok(tmp === 0, "tmp !=== 0");
607 ok(tmp === 1, "tmp !== 4");
614 ok(false, "break did not break");
616 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
618 ok(tmp === 4, "tmp !== 4");
620 for(tmp=0; tmp < 4; tmp++)
621 ok(tmp < 4, "tmp = " + tmp);
622 ok(tmp === 4, "tmp !== 4");
624 for(tmp=0; tmp < 4; tmp++) {
627 ok(tmp < 2, "tmp = " + tmp);
629 ok(tmp === 2, "tmp !== 2");
631 for(tmp=0; tmp < 4; tmp++) {
634 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
636 ok(tmp === 4, "tmp !== 4");
638 for(var fi=0; fi < 4; fi++)
639 ok(fi < 4, "fi = " + fi);
640 ok(fi === 4, "fi !== 4");
642 ok((void 1) === undefined, "(void 1) !== undefined");
644 var inobj = new Object();
646 for(var iter in inobj)
647 ok(false, "unexpected iter = " + iter);
652 ok(iter == "test", "unexpected iter = " + iter);
655 ok(tmp === 1, "for..in tmp = " + tmp);
657 function forinTestObj() {}
659 forinTestObj.prototype.test3 = true;
661 var arr = new Array();
662 inobj = new forinTestObj();
672 ok(tmp === 3, "for..in tmp = " + tmp);
673 ok(arr["test1"] === true, "arr[test1] !== true");
674 ok(arr["test2"] === true, "arr[test2] !== true");
675 ok(arr["test3"] === true, "arr[test3] !== true");
679 ok((delete tmp.test) === true, "delete returned false");
680 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
682 ok(false, "tmp has prop " + iter);
686 ok(testWith === true, "testWith !== true");