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
22 ok(i === 0, "parseInt('0') = " + i);
24 ok(i === 123, "parseInt('123') = " + i);
26 ok(i === -123, "parseInt('-123') = " + i);
28 ok(i === 0xff, "parseInt('0xff') = " + i);
29 i = parseInt("11", 8);
30 ok(i === 9, "parseInt('11', 8) = " + i);
31 i = parseInt("1j", 22);
32 ok(i === 41, "parseInt('1j', 32) = " + i);
33 i = parseInt("123", 0);
34 ok(i === 123, "parseInt('123', 0) = " + i);
35 i = parseInt("123", 10, "test");
36 ok(i === 123, "parseInt('123', 10, 'test') = " + i);
37 i = parseInt("11", "8");
38 ok(i === 9, "parseInt('11', '8') = " + i);
40 tmp = encodeURI("abc");
41 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
42 tmp = encodeURI("{abc}");
43 ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
45 ok(tmp === "", "encodeURI('') = " + tmp);
46 tmp = encodeURI("\01\02\03\04");
47 ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
48 tmp = encodeURI("{#@}");
49 ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
50 tmp = encodeURI("\xa1 ");
51 ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
52 tmp = encodeURI("\xffff");
53 ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
54 tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
55 ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
57 ok(tmp === "undefined", "encodeURI() = " + tmp);
58 tmp = encodeURI("abc", "test");
59 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
61 tmp = "" + new Object();
62 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
64 ok("".length === 0, "\"\".length = " + "".length);
65 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
66 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
67 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
70 ok(tmp === "", "''.toString() = " + tmp);
71 tmp = "test".toString();
72 ok(tmp === "test", "''.toString() = " + tmp);
73 tmp = "test".toString(3);
74 ok(tmp === "test", "''.toString(3) = " + tmp);
77 ok(tmp === "", "''.valueOf() = " + tmp);
78 tmp = "test".valueOf();
79 ok(tmp === "test", "''.valueOf() = " + tmp);
80 tmp = "test".valueOf(3);
81 ok(tmp === "test", "''.valueOf(3) = " + tmp);
83 var str = new String("test");
84 ok(str.toString() === "test", "str.toString() = " + str.toString());
85 var str = new String();
86 ok(str.toString() === "", "str.toString() = " + str.toString());
87 var str = new String("test", "abc");
88 ok(str.toString() === "test", "str.toString() = " + str.toString());
91 ok(tmp === "value test", "'value ' + str = " + tmp);
94 ok(tmp === "", "String() = " + tmp);
96 ok(tmp === "false", "String(false) = " + tmp);
98 ok(tmp === "null", "String(null) = " + tmp);
100 ok(tmp === "test", "String('test') = " + tmp);
101 tmp = String("test", "abc");
102 ok(tmp === "test", "String('test','abc') = " + tmp);
104 tmp = "abc".charAt(0);
105 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
106 tmp = "abc".charAt(1);
107 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
108 tmp = "abc".charAt(2);
109 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
110 tmp = "abc".charAt(3);
111 ok(tmp === "", "'abc',charAt(3) = " + tmp);
112 tmp = "abc".charAt(4);
113 ok(tmp === "", "'abc',charAt(4) = " + tmp);
114 tmp = "abc".charAt();
115 ok(tmp === "a", "'abc',charAt() = " + tmp);
116 tmp = "abc".charAt(-1);
117 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
118 tmp = "abc".charAt(0,2);
119 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
121 tmp = "abc".charCodeAt(0);
122 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
123 tmp = "abc".charCodeAt(1);
124 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
125 tmp = "abc".charCodeAt(2);
126 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
127 tmp = "abc".charCodeAt();
128 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
129 tmp = "abc".charCodeAt(true);
130 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
131 tmp = "abc".charCodeAt(0,2);
132 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
134 tmp = "abcd".substring(1,3);
135 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
136 tmp = "abcd".substring(-1,3);
137 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
138 tmp = "abcd".substring(1,6);
139 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
140 tmp = "abcd".substring(3,1);
141 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
142 tmp = "abcd".substring(2,2);
143 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
144 tmp = "abcd".substring(true,"3");
145 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
146 tmp = "abcd".substring(1,3,2);
147 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
148 tmp = "abcd".substring();
149 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
151 tmp = "abcd".slice(1,3);
152 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
153 tmp = "abcd".slice(1,-1);
154 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
155 tmp = "abcd".slice(-3,3);
156 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
157 tmp = "abcd".slice(-6,3);
158 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
159 tmp = "abcd".slice(3,1);
160 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
161 tmp = "abcd".slice(true,3);
162 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
163 tmp = "abcd".slice();
164 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
165 tmp = "abcd".slice(1);
166 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
168 tmp = "abc".concat(["d",1],2,false);
169 ok(tmp === "abcd,12false", "concat returned " + tmp);
170 var arr = new Array(2,"a");
171 arr.concat = String.prototype.concat;
172 tmp = arr.concat("d");
173 ok(tmp === "2,ad", "arr.concat = " + tmp);
175 m = "a+bcabc".match("a+");
176 ok(typeof(m) === "object", "typeof m is not object");
177 ok(m.length === 1, "m.length is not 1");
178 ok(m["0"] === "a", "m[0] is not \"ab\"");
180 r = "- [test] -".replace("[test]", "success");
181 ok(r === "- success -", "r = " + r + " expected '- success -'");
183 r = "- [test] -".replace("[test]", "success", "test");
184 ok(r === "- success -", "r = " + r + " expected '- success -'");
186 r = "test".replace();
187 ok(r === "test", "r = " + r + " expected 'test'");
189 function replaceFunc3(m, off, str) {
190 ok(arguments.length === 3, "arguments.length = " + arguments.length);
191 ok(m === "[test]", "m = " + m + " expected [test1]");
192 ok(off === 1, "off = " + off + " expected 0");
193 ok(str === "-[test]-", "str = " + arguments[3]);
197 r = "-[test]-".replace("[test]", replaceFunc3);
198 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
200 r = "-[test]-".replace("[test]", replaceFunc3, "test");
201 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
203 r = "1,2,3".split(",");
204 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
205 ok(r.length === 3, "r.length = " + r.length);
206 ok(r[0] === "1", "r[0] = " + r[0]);
207 ok(r[1] === "2", "r[1] = " + r[1]);
208 ok(r[2] === "3", "r[2] = " + r[2]);
211 r = "1,2,3".split(",*");
212 ok(r.length === 1, "r.length = " + r.length);
213 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
216 ok(r.length === 3, "r.length = " + r.length);
217 ok(r[0] === "1", "r[0] = " + r[0]);
218 ok(r[1] === "2", "r[1] = " + r[1]);
219 ok(r[2] === "3", "r[2] = " + r[2]);
222 ok(r.length === 2, "r.length = " + r.length);
223 ok(r[0] === "1", "r[0] = " + r[0]);
224 ok(r[1] === "3", "r[1] = " + r[1]);
226 r = "1,2,".split(",");
227 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
228 ok(r.length === 3, "r.length = " + r.length);
229 ok(r[0] === "1", "r[0] = " + r[0]);
230 ok(r[1] === "2", "r[1] = " + r[1]);
231 ok(r[2] === "", "r[2] = " + r[2]);
233 tmp = "abcd".indexOf("bc",0);
234 ok(tmp === 1, "indexOf = " + tmp);
235 tmp = "abcd".indexOf("bc",1);
236 ok(tmp === 1, "indexOf = " + tmp);
237 tmp = "abcd".indexOf("bc");
238 ok(tmp === 1, "indexOf = " + tmp);
239 tmp = "abcd".indexOf("ac");
240 ok(tmp === -1, "indexOf = " + tmp);
241 tmp = "abcd".indexOf("bc",2);
242 ok(tmp === -1, "indexOf = " + tmp);
243 tmp = "abcd".indexOf("a",0);
244 ok(tmp === 0, "indexOf = " + tmp);
245 tmp = "abcd".indexOf("bc",0,"test");
246 ok(tmp === 1, "indexOf = " + tmp);
247 tmp = "abcd".indexOf();
248 ok(tmp == -1, "indexOf = " + tmp);
250 tmp = "".toLowerCase();
251 ok(tmp === "", "''.toLowerCase() = " + tmp);
252 tmp = "test".toLowerCase();
253 ok(tmp === "test", "''.toLowerCase() = " + tmp);
254 tmp = "test".toLowerCase(3);
255 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
256 tmp = "tEsT".toLowerCase();
257 ok(tmp === "test", "''.toLowerCase() = " + tmp);
258 tmp = "tEsT".toLowerCase(3);
259 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
261 tmp = "".toUpperCase();
262 ok(tmp === "", "''.toUpperCase() = " + tmp);
263 tmp = "TEST".toUpperCase();
264 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
265 tmp = "TEST".toUpperCase(3);
266 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
267 tmp = "tEsT".toUpperCase();
268 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
269 tmp = "tEsT".toUpperCase(3);
270 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
273 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
275 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
277 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
279 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
282 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
284 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
285 tmp = "test".blink();
286 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
287 tmp = "test".blink(3);
288 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
291 ok(tmp === "<B></B>", "''.bold() = " + tmp);
293 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
295 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
296 tmp = "test".bold(3);
297 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
300 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
302 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
303 tmp = "test".fixed();
304 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
305 tmp = "test".fixed(3);
306 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
309 ok(tmp === "<I></I>", "''.italics() = " + tmp);
311 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
312 tmp = "test".italics();
313 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
314 tmp = "test".italics(3);
315 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
318 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
320 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
321 tmp = "test".small();
322 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
323 tmp = "test".small(3);
324 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
327 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
329 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
330 tmp = "test".strike();
331 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
332 tmp = "test".strike(3);
333 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
336 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
338 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
340 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
342 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
345 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
347 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
349 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
351 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
353 var arr = new Array();
354 ok(typeof(arr) === "object", "arr () is not object");
355 ok((arr.length === 0), "arr.length is not 0");
356 ok(arr["0"] === undefined, "arr[0] is not undefined");
358 var arr = new Array(1, 2, "test");
359 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
360 ok((arr.length === 3), "arr.length is not 3");
361 ok(arr["0"] === 1, "arr[0] is not 1");
362 ok(arr["1"] === 2, "arr[1] is not 2");
363 ok(arr["2"] === "test", "arr[2] is not \"test\"");
366 ok((arr.length === 8), "arr.length is not 8");
369 ok(tmp === "", "'' + [] = " + tmp);
371 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
373 var arr = new Array(6);
374 ok(typeof(arr) === "object", "arr (6) is not object");
375 ok((arr.length === 6), "arr.length is not 6");
376 ok(arr["0"] === undefined, "arr[0] is not undefined");
378 ok(arr.push() === 6, "arr.push() !== 6");
379 ok(arr.push(1) === 7, "arr.push(1) !== 7");
380 ok(arr[6] === 1, "arr[6] != 1");
381 ok(arr.length === 7, "arr.length != 10");
382 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
383 ok(arr[8] === "b", "arr[8] != 'b'");
384 ok(arr.length === 10, "arr.length != 10");
388 ok(arr.length === 2, "arr.length = " + arr.length);
389 ok(tmp === 5, "pop() = " + tmp);
391 ok(arr.length === 1, "arr.length = " + arr.length);
392 ok(tmp === 4, "pop() = " + tmp);
394 ok(arr.length === 0, "arr.length = " + arr.length);
395 ok(tmp === 3, "pop() = " + tmp);
397 ok(false, "not deleted " + tmp);
399 ok(arr.length === 0, "arr.length = " + arr.length);
400 ok(tmp === undefined, "tmp = " + tmp);
403 ok(arr.length === 5, "arr.length = " + arr.length);
404 ok(tmp === undefined, "tmp = " + tmp);
406 arr = [1,2,null,false,undefined,,"a"];
409 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
411 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
412 tmp = arr.join(";","test");
413 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
415 ok(tmp === "12falsea", "arr.join('') = " + tmp);
417 tmp = arr.toString();
418 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
419 tmp = arr.toString("test");
420 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
422 arr = [5,true,2,-1,3,false,"2.5"];
423 tmp = arr.sort(function(x,y) { return y-x; });
424 ok(tmp === arr, "tmp !== arr");
425 tmp = [5,3,"2.5",2,true,false,-1];
426 for(var i=0; i < arr.length; i++)
427 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
429 arr = [5,false,2,0,"abc",3,"a",-1];
431 ok(tmp === arr, "tmp !== arr");
432 tmp = [-1,0,2,3,5,"a","abc",false];
433 for(var i=0; i < arr.length; i++)
434 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
436 arr = ["a", "b", "ab"];
437 tmp = ["a", "ab", "b"];
438 ok(arr.sort() === arr, "arr.sort() !== arr");
439 for(var i=0; i < arr.length; i++)
440 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
442 var num = new Number(6);
444 tmp = arr.concat(3, [4,5], num);
445 ok(tmp !== arr, "tmp === arr");
446 for(var i=0; i<6; i++)
447 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
448 ok(tmp[6] === num, "tmp[6] !== num");
449 ok(tmp.length === 7, "tmp.length = " + tmp.length);
452 ok(arr.length === 0, "arr.length = " + arr.length);
455 tmp = arr.concat([2]);
456 ok(tmp.length === 3, "tmp.length = " + tmp.length);
457 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
459 var num = new Number(2);
460 ok(num.toString() === "2", "num(2).toString !== 2");
461 var num = new Number();
462 ok(num.toString() === "0", "num().toString !== 0");
464 ok(Number() === 0, "Number() = " + Number());
465 ok(Number(false) === 0, "Number(false) = " + Number(false));
466 ok(Number("43") === 43, "Number('43') = " + Number("43"));
468 tmp = (new Number(1)).valueOf();
469 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
470 tmp = (new Number(1,2)).valueOf();
471 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
472 tmp = (new Number()).valueOf();
473 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
474 tmp = Number.prototype.valueOf();
475 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
478 ok(tmp === 1, "Math.min(1) = " + tmp);
480 tmp = Math.min(1, false);
481 ok(tmp === 0, "Math.min(1, false) = " + tmp);
484 ok(tmp === Infinity, "Math.min() = " + tmp);
486 tmp = Math.min(1, NaN, -Infinity, false);
487 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
489 tmp = Math.min(1, false, true, null, -3);
490 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
493 ok(tmp === 1, "Math.max(1) = " + tmp);
495 tmp = Math.max(true, 0);
496 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
498 tmp = Math.max(-2, false, true, null, 1);
499 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
502 ok(tmp === -Infinity, "Math.max() = " + tmp);
504 tmp = Math.max(true, NaN, 0);
505 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
507 tmp = Math.round(0.5);
508 ok(tmp === 1, "Math.round(0.5) = " + tmp);
510 tmp = Math.round(-0.5);
511 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
513 tmp = Math.round(1.1);
514 ok(tmp === 1, "Math.round(1.1) = " + tmp);
516 tmp = Math.round(true);
517 ok(tmp === 1, "Math.round(true) = " + tmp);
519 tmp = Math.round(1.1, 3, 4);
520 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
523 ok(isNaN(tmp), "Math.round() is not NaN");
525 tmp = Math.ceil(0.5);
526 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
528 tmp = Math.ceil(-0.5);
529 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
531 tmp = Math.ceil(1.1);
532 ok(tmp === 2, "Math.round(1.1) = " + tmp);
534 tmp = Math.ceil(true);
535 ok(tmp === 1, "Math.ceil(true) = " + tmp);
537 tmp = Math.ceil(1.1, 3, 4);
538 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
541 ok(isNaN(tmp), "ceil() is not NaN");
543 tmp = Math.floor(0.5);
544 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
546 tmp = Math.floor(-0.5);
547 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
549 tmp = Math.floor(1.1);
550 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
552 tmp = Math.floor(true);
553 ok(tmp === 1, "Math.floor(true) = " + tmp);
555 tmp = Math.floor(1.1, 3, 4);
556 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
559 ok(isNaN(tmp), "floor is not NaN");
562 ok(tmp === 3, "Math.abs(3) = " + tmp);
565 ok(tmp === 3, "Math.abs(-3) = " + tmp);
567 tmp = Math.abs(true);
568 ok(tmp === 1, "Math.abs(true) = " + tmp);
571 ok(isNaN(tmp), "Math.abs() is not NaN");
574 ok(isNaN(tmp), "Math.abs() is not NaN");
576 tmp = Math.abs(-Infinity);
577 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
579 tmp = Math.abs(-3, 2);
580 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
583 ok(tmp === 1, "Math.cos(0) = " + tmp);
585 tmp = Math.cos(Math.PI/2);
586 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
588 tmp = Math.cos(-Math.PI/2);
589 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
591 tmp = Math.cos(Math.PI/3, 2);
592 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
594 tmp = Math.cos(true);
595 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
597 tmp = Math.cos(false);
598 ok(tmp === 1, "Math.cos(false) = " + tmp);
601 ok(isNaN(tmp), "Math.cos() is not NaN");
604 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
606 tmp = Math.cos(Infinity);
607 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
609 tmp = Math.cos(-Infinity);
610 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
612 tmp = Math.pow(2, 2);
613 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
615 tmp = Math.pow(4, 0.5);
616 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
618 tmp = Math.pow(2, 2, 3);
619 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
622 ok(isNaN(tmp), "Math.pow(2) is not NaN");
625 ok(isNaN(tmp), "Math.pow() is not NaN");
628 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
629 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
631 tmp = Math.random(100);
632 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
633 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
636 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
639 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
642 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
644 tmp = Math.acos(Math.PI/4, 2);
645 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
647 tmp = Math.acos(true);
648 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
650 tmp = Math.acos(false);
651 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
653 tmp = Math.acos(1.1);
654 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
657 ok(isNaN(tmp), "Math.acos() is not NaN");
659 tmp = Math.acos(NaN);
660 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
662 tmp = Math.acos(Infinity);
663 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
665 tmp = Math.acos(-Infinity);
666 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
669 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
672 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
675 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
677 tmp = Math.asin(Math.PI/4, 2);
678 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
680 tmp = Math.asin(true);
681 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
683 tmp = Math.asin(false);
684 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
686 tmp = Math.asin(1.1);
687 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
690 ok(isNaN(tmp), "Math.asin() is not NaN");
692 tmp = Math.asin(NaN);
693 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
695 tmp = Math.asin(Infinity);
696 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
698 tmp = Math.asin(-Infinity);
699 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
702 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
705 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
708 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
710 tmp = Math.atan(true);
711 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
713 tmp = Math.atan(false);
714 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
717 ok(isNaN(tmp), "Math.atan() is not NaN");
719 tmp = Math.atan(NaN);
720 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
722 tmp = Math.atan(Infinity);
723 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
725 tmp = Math.atan(-Infinity);
726 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
728 tmp = Math.atan2(0, 0);
729 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
731 tmp = Math.atan2(0, 1);
732 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
734 tmp = Math.atan2(0, Infinity);
735 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
737 tmp = Math.atan2(0, -1);
738 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
740 tmp = Math.atan2(0, -Infinity);
741 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
743 tmp = Math.atan2(1, 0);
744 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
746 tmp = Math.atan2(Infinity, 0);
747 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
749 tmp = Math.atan2(-1, 0);
750 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
752 tmp = Math.atan2(-Infinity, 0);
753 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
755 tmp = Math.atan2(1, 1);
756 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
758 tmp = Math.atan2(-1, -1);
759 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
761 tmp = Math.atan2(-1, 1);
762 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
764 tmp = Math.atan2(Infinity, Infinity);
765 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
767 tmp = Math.atan2(Infinity, -Infinity, 1);
768 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
771 ok(isNaN(tmp), "Math.atan2() is not NaN");
774 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
777 ok(tmp === 1, "Math.exp(0) = " + tmp);
780 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
783 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
785 tmp = Math.exp(true);
786 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
788 tmp = Math.exp(1, 1);
789 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
792 ok(isNaN(tmp), "Math.exp() is not NaN");
795 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
797 tmp = Math.exp(Infinity);
798 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
800 tmp = Math.exp(-Infinity);
801 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
804 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
807 ok(isNaN(tmp), "Math.log(-1) is not NaN");
809 tmp = Math.log(true);
810 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
812 tmp = Math.log(1, 1);
813 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
816 ok(isNaN(tmp), "Math.log() is not NaN");
819 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
821 tmp = Math.log(Infinity);
822 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
824 tmp = Math.log(-Infinity);
825 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
828 ok(tmp === 0, "Math.sin(0) = " + tmp);
830 tmp = Math.sin(Math.PI/2);
831 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
833 tmp = Math.sin(-Math.PI/2);
834 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
836 tmp = Math.sin(Math.PI/3, 2);
837 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
839 tmp = Math.sin(true);
840 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
842 tmp = Math.sin(false);
843 ok(tmp === 0, "Math.sin(false) = " + tmp);
846 ok(isNaN(tmp), "Math.sin() is not NaN");
849 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
851 tmp = Math.sin(Infinity);
852 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
854 tmp = Math.sin(-Infinity);
855 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
858 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
861 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
864 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
866 tmp = Math.sqrt(2, 2);
867 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
869 tmp = Math.sqrt(true);
870 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
872 tmp = Math.sqrt(false);
873 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
876 ok(isNaN(tmp), "Math.sqrt() is not NaN");
878 tmp = Math.sqrt(NaN);
879 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
881 tmp = Math.sqrt(Infinity);
882 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
884 tmp = Math.sqrt(-Infinity);
885 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
888 ok(tmp === 0, "Math.tan(0) = " + tmp);
890 tmp = Math.tan(Math.PI);
891 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
893 tmp = Math.tan(2, 2);
894 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
896 tmp = Math.tan(true);
897 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
899 tmp = Math.tan(false);
900 ok(tmp === 0, "Math.tan(false) = " + tmp);
903 ok(isNaN(tmp), "Math.tan() is not NaN");
906 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
908 tmp = Math.tan(Infinity);
909 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
911 tmp = Math.tan(-Infinity);
912 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
914 var func = function (a) {
918 ok(func.toString() === "function (a) {\n var a = 1;\n if(a) return;\n }",
919 "func.toString() = " + func.toString());
920 ok("" + func === "function (a) {\n var a = 1;\n if(a) return;\n }",
921 "'' + func.toString() = " + func);
923 function testFuncToString(x,y) {
927 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n return x+y;\n}",
928 "testFuncToString.toString() = " + testFuncToString.toString());
929 ok("" + testFuncToString === "function testFuncToString(x,y) {\n return x+y;\n}",
930 "'' + testFuncToString = " + testFuncToString);
932 var date = new Date();
934 date = new Date(100);
935 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
936 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
937 date = new Date(8.64e15);
938 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
939 date = new Date(8.64e15+1);
940 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
941 date = new Date(Infinity);
942 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
944 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
945 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
946 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
948 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
949 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
950 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
951 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
952 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
953 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
954 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
955 date.setTime(60*24*60*60*1000);
956 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
957 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
958 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
959 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
960 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
961 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
962 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
963 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
964 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
965 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
966 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
967 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
968 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
969 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
970 date.setTime(Infinity);
971 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
972 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
973 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
974 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
975 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
976 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
978 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
979 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
981 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
983 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
984 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
986 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
988 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
989 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
991 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
993 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
994 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
995 Math.LOG10E = "test";
996 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
998 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
999 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
1001 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
1003 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
1004 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
1006 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
1008 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
1009 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
1010 Math.SQRT2 = "test";
1011 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
1013 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
1014 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
1015 Math.SQRT1_2 = "test";
1016 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);