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 = "" + new Object();
41 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
43 ok("".length === 0, "\"\".length = " + "".length);
44 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
45 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
46 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
49 ok(tmp === "", "''.toString() = " + tmp);
50 tmp = "test".toString();
51 ok(tmp === "test", "''.toString() = " + tmp);
52 tmp = "test".toString(3);
53 ok(tmp === "test", "''.toString(3) = " + tmp);
56 ok(tmp === "", "''.valueOf() = " + tmp);
57 tmp = "test".valueOf();
58 ok(tmp === "test", "''.valueOf() = " + tmp);
59 tmp = "test".valueOf(3);
60 ok(tmp === "test", "''.valueOf(3) = " + tmp);
62 var str = new String("test");
63 ok(str.toString() === "test", "str.toString() = " + str.toString());
64 var str = new String();
65 ok(str.toString() === "", "str.toString() = " + str.toString());
66 var str = new String("test", "abc");
67 ok(str.toString() === "test", "str.toString() = " + str.toString());
70 ok(tmp === "value test", "'value ' + str = " + tmp);
73 ok(tmp === "", "String() = " + tmp);
75 ok(tmp === "false", "String(false) = " + tmp);
77 ok(tmp === "null", "String(null) = " + tmp);
79 ok(tmp === "test", "String('test') = " + tmp);
80 tmp = String("test", "abc");
81 ok(tmp === "test", "String('test','abc') = " + tmp);
83 tmp = "abc".charAt(0);
84 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
85 tmp = "abc".charAt(1);
86 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
87 tmp = "abc".charAt(2);
88 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
89 tmp = "abc".charAt(3);
90 ok(tmp === "", "'abc',charAt(3) = " + tmp);
91 tmp = "abc".charAt(4);
92 ok(tmp === "", "'abc',charAt(4) = " + tmp);
94 ok(tmp === "a", "'abc',charAt() = " + tmp);
95 tmp = "abc".charAt(-1);
96 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
97 tmp = "abc".charAt(0,2);
98 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
100 tmp = "abc".charCodeAt(0);
101 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
102 tmp = "abc".charCodeAt(1);
103 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
104 tmp = "abc".charCodeAt(2);
105 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
106 tmp = "abc".charCodeAt();
107 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
108 tmp = "abc".charCodeAt(true);
109 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
110 tmp = "abc".charCodeAt(0,2);
111 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
113 tmp = "abcd".substring(1,3);
114 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
115 tmp = "abcd".substring(-1,3);
116 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
117 tmp = "abcd".substring(1,6);
118 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
119 tmp = "abcd".substring(3,1);
120 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
121 tmp = "abcd".substring(2,2);
122 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
123 tmp = "abcd".substring(true,"3");
124 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
125 tmp = "abcd".substring(1,3,2);
126 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
127 tmp = "abcd".substring();
128 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
130 tmp = "abcd".slice(1,3);
131 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
132 tmp = "abcd".slice(1,-1);
133 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
134 tmp = "abcd".slice(-3,3);
135 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
136 tmp = "abcd".slice(-6,3);
137 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
138 tmp = "abcd".slice(3,1);
139 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
140 tmp = "abcd".slice(true,3);
141 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
142 tmp = "abcd".slice();
143 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
144 tmp = "abcd".slice(1);
145 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
147 tmp = "abc".concat(["d",1],2,false);
148 ok(tmp === "abcd,12false", "concat returned " + tmp);
149 var arr = new Array(2,"a");
150 arr.concat = String.prototype.concat;
151 tmp = arr.concat("d");
152 ok(tmp === "2,ad", "arr.concat = " + tmp);
154 m = "a+bcabc".match("a+");
155 ok(typeof(m) === "object", "typeof m is not object");
156 ok(m.length === 1, "m.length is not 1");
157 ok(m["0"] === "a", "m[0] is not \"ab\"");
159 r = "- [test] -".replace("[test]", "success");
160 ok(r === "- success -", "r = " + r + " expected '- success -'");
162 r = "- [test] -".replace("[test]", "success", "test");
163 ok(r === "- success -", "r = " + r + " expected '- success -'");
165 r = "test".replace();
166 ok(r === "test", "r = " + r + " expected 'test'");
168 function replaceFunc3(m, off, str) {
169 ok(arguments.length === 3, "arguments.length = " + arguments.length);
170 ok(m === "[test]", "m = " + m + " expected [test1]");
171 ok(off === 1, "off = " + off + " expected 0");
172 ok(str === "-[test]-", "str = " + arguments[3]);
176 r = "-[test]-".replace("[test]", replaceFunc3);
177 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
179 r = "-[test]-".replace("[test]", replaceFunc3, "test");
180 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
182 var arr = new Array();
183 ok(typeof(arr) === "object", "arr () is not object");
184 ok((arr.length === 0), "arr.length is not 0");
185 ok(arr["0"] === undefined, "arr[0] is not undefined");
187 var arr = new Array(1, 2, "test");
188 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
189 ok((arr.length === 3), "arr.length is not 3");
190 ok(arr["0"] === 1, "arr[0] is not 1");
191 ok(arr["1"] === 2, "arr[1] is not 2");
192 ok(arr["2"] === "test", "arr[2] is not \"test\"");
195 ok((arr.length === 8), "arr.length is not 8");
198 ok(tmp === "", "'' + [] = " + tmp);
200 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
202 var arr = new Array(6);
203 ok(typeof(arr) === "object", "arr (6) is not object");
204 ok((arr.length === 6), "arr.length is not 6");
205 ok(arr["0"] === undefined, "arr[0] is not undefined");
207 ok(arr.push() === 6, "arr.push() !== 6");
208 ok(arr.push(1) === 7, "arr.push(1) !== 7");
209 ok(arr[6] === 1, "arr[6] != 1");
210 ok(arr.length === 7, "arr.length != 10");
211 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
212 ok(arr[8] === "b", "arr[8] != 'b'");
213 ok(arr.length === 10, "arr.length != 10");
215 arr = [1,2,null,false,undefined,,"a"];
218 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
220 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
221 tmp = arr.join(";","test");
222 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
224 ok(tmp === "12falsea", "arr.join('') = " + tmp);
226 tmp = arr.toString();
227 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
228 tmp = arr.toString("test");
229 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
231 arr = [5,true,2,-1,3,false,"2.5"];
232 tmp = arr.sort(function(x,y) { return y-x; });
233 ok(tmp === arr, "tmp !== arr");
234 tmp = [5,3,"2.5",2,true,false,-1];
235 for(var i=0; i < arr.length; i++)
236 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
238 arr = [5,false,2,0,"abc",3,"a",-1];
240 ok(tmp === arr, "tmp !== arr");
241 tmp = [-1,0,2,3,5,"a","abc",false];
242 for(var i=0; i < arr.length; i++)
243 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
245 arr = ["a", "b", "ab"];
246 tmp = ["a", "ab", "b"];
247 ok(arr.sort() === arr, "arr.sort() !== arr");
248 for(var i=0; i < arr.length; i++)
249 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
251 var num = new Number(6);
253 tmp = arr.concat(3, [4,5], num);
254 ok(tmp !== arr, "tmp === arr");
255 for(var i=0; i<6; i++)
256 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
257 ok(tmp[6] === num, "tmp[6] !== num");
258 ok(tmp.length === 7, "tmp.length = " + tmp.length);
261 ok(arr.length === 0, "arr.length = " + arr.lrngth);
264 tmp = arr.concat([2]);
265 ok(tmp.length === 3, "tmp.length = " + tmp.length);
266 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
268 var num = new Number(2);
269 ok(num.toString() === "2", "num(2).toString !== 2");
270 var num = new Number();
271 ok(num.toString() === "0", "num().toString !== 0");
273 ok(Number() === 0, "Number() = " + Number());
274 ok(Number(false) === 0, "Number(false) = " + Number(false));
275 ok(Number("43") === 43, "Number('43') = " + Number("43"));
278 ok(tmp === 1, "Math.min(1) = " + tmp);
280 tmp = Math.min(1, false);
281 ok(tmp === 0, "Math.min(1, false) = " + tmp);
283 tmp = Math.min(1, false, true, null, -3);
284 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
287 ok(tmp === 1, "Math.max(1) = " + tmp);
289 tmp = Math.max(true, 0);
290 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
292 tmp = Math.max(-2, false, true, null, 1);
293 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
295 tmp = Math.round(0.5);
296 ok(tmp === 1, "Math.round(0.5) = " + tmp);
298 tmp = Math.round(-0.5);
299 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
301 tmp = Math.round(1.1);
302 ok(tmp === 1, "Math.round(1.1) = " + tmp);
304 tmp = Math.round(true);
305 ok(tmp === 1, "Math.round(true) = " + tmp);
307 tmp = Math.round(1.1, 3, 4);
308 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
310 tmp = Math.ceil(0.5);
311 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
313 tmp = Math.ceil(-0.5);
314 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
316 tmp = Math.ceil(1.1);
317 ok(tmp === 2, "Math.round(1.1) = " + tmp);
319 tmp = Math.ceil(true);
320 ok(tmp === 1, "Math.ceil(true) = " + tmp);
322 tmp = Math.ceil(1.1, 3, 4);
323 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
326 ok(tmp === 3, "Math.abs(3) = " + tmp);
329 ok(tmp === 3, "Math.abs(-3) = " + tmp);
331 tmp = Math.abs(true);
332 ok(tmp === 1, "Math.abs(true) = " + tmp);
334 tmp = Math.abs(-3, 2);
335 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
337 tmp = Math.pow(2, 2);
338 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
340 tmp = Math.pow(4, 0.5);
341 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
343 tmp = Math.pow(2, 2, 3);
344 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
346 var func = function (a) {
350 ok(func.toString() === "function (a) {\n var a = 1;\n if(a) return;\n }",
351 "func.toString() = " + func.toString());
352 ok("" + func === "function (a) {\n var a = 1;\n if(a) return;\n }",
353 "'' + func.toString() = " + func);
355 function testFuncToString(x,y) {
359 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n return x+y;\n}",
360 "testFuncToString.toString() = " + testFuncToString.toString());
361 ok("" + testFuncToString === "function testFuncToString(x,y) {\n return x+y;\n}",
362 "'' + testFuncToString = " + testFuncToString);