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 tmp = "abc".charAt(0);
63 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
64 tmp = "abc".charAt(1);
65 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
66 tmp = "abc".charAt(2);
67 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
68 tmp = "abc".charAt(3);
69 ok(tmp === "", "'abc',charAt(3) = " + tmp);
70 tmp = "abc".charAt(4);
71 ok(tmp === "", "'abc',charAt(4) = " + tmp);
73 ok(tmp === "a", "'abc',charAt() = " + tmp);
74 tmp = "abc".charAt(-1);
75 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
76 tmp = "abc".charAt(0,2);
77 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
79 tmp = "abc".charCodeAt(0);
80 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
81 tmp = "abc".charCodeAt(1);
82 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
83 tmp = "abc".charCodeAt(2);
84 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
85 tmp = "abc".charCodeAt();
86 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
87 tmp = "abc".charCodeAt(true);
88 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
89 tmp = "abc".charCodeAt(0,2);
90 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
92 tmp = "abcd".substring(1,3);
93 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
94 tmp = "abcd".substring(-1,3);
95 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
96 tmp = "abcd".substring(1,6);
97 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
98 tmp = "abcd".substring(3,1);
99 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
100 tmp = "abcd".substring(2,2);
101 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
102 tmp = "abcd".substring(true,"3");
103 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
104 tmp = "abcd".substring(1,3,2);
105 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
106 tmp = "abcd".substring();
107 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
109 tmp = "abcd".slice(1,3);
110 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
111 tmp = "abcd".slice(1,-1);
112 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
113 tmp = "abcd".slice(-3,3);
114 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
115 tmp = "abcd".slice(-6,3);
116 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
117 tmp = "abcd".slice(3,1);
118 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
119 tmp = "abcd".slice(true,3);
120 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
121 tmp = "abcd".slice();
122 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
123 tmp = "abcd".slice(1);
124 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
126 var arr = new Array();
127 ok(typeof(arr) === "object", "arr () is not object");
128 ok((arr.length === 0), "arr.length is not 0");
129 ok(arr["0"] === undefined, "arr[0] is not undefined");
131 var arr = new Array(1, 2, "test");
132 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
133 ok((arr.length === 3), "arr.length is not 3");
134 ok(arr["0"] === 1, "arr[0] is not 1");
135 ok(arr["1"] === 2, "arr[1] is not 2");
136 ok(arr["2"] === "test", "arr[2] is not \"test\"");
139 ok((arr.length === 8), "arr.length is not 8");
142 ok(tmp === "", "'' + [] = " + tmp);
144 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
146 var arr = new Array(6);
147 ok(typeof(arr) === "object", "arr (6) is not object");
148 ok((arr.length === 6), "arr.length is not 6");
149 ok(arr["0"] === undefined, "arr[0] is not undefined");
151 ok(arr.push() === 6, "arr.push() !== 6");
152 ok(arr.push(1) === 7, "arr.push(1) !== 7");
153 ok(arr[6] === 1, "arr[6] != 1");
154 ok(arr.length === 7, "arr.length != 10");
155 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
156 ok(arr[8] === "b", "arr[8] != 'b'");
157 ok(arr.length === 10, "arr.length != 10");
159 arr = [1,2,null,false,undefined,,"a"];
162 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
164 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
165 tmp = arr.join(";","test");
166 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
168 ok(tmp === "12falsea", "arr.join('') = " + tmp);
170 tmp = arr.toString();
171 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
172 tmp = arr.toString("test");
173 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
175 arr = [5,true,2,-1,3,false,"2.5"];
176 tmp = arr.sort(function(x,y) { return y-x; });
177 ok(tmp === arr, "tmp !== arr");
178 tmp = [5,3,"2.5",2,true,false,-1];
179 for(var i=0; i < arr.length; i++)
180 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
182 arr = [5,false,2,0,"abc",3,"a",-1];
184 ok(tmp === arr, "tmp !== arr");
185 tmp = [-1,0,2,3,5,"a","abc",false];
186 for(var i=0; i < arr.length; i++)
187 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
189 arr = ["a", "b", "ab"];
190 tmp = ["a", "ab", "b"];
191 ok(arr.sort() === arr, "arr.sort() !== arr");
192 for(var i=0; i < arr.length; i++)
193 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
195 var num = new Number(6);
197 tmp = arr.concat(3, [4,5], num);
198 ok(tmp !== arr, "tmp === arr");
199 for(var i=0; i<6; i++)
200 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
201 ok(tmp[6] === num, "tmp[6] !== num");
202 ok(tmp.length === 7, "tmp.length = " + tmp.length);
205 ok(arr.length === 0, "arr.length = " + arr.lrngth);
208 tmp = arr.concat([2]);
209 ok(tmp.length === 3, "tmp.length = " + tmp.length);
210 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
212 var num = new Number(2);
213 ok(num.toString() === "2", "num(2).toString !== 2");
214 var num = new Number();
215 ok(num.toString() === "0", "num().toString !== 0");
217 ok(Number() === 0, "Number() = " + Number());
218 ok(Number(false) === 0, "Number(false) = " + Number(false));
219 ok(Number("43") === 43, "Number('43') = " + Number("43"));