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 tmp = "" + new Object();
22 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
24 ok("".length === 0, "\"\".length = " + "".length);
25 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
26 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
27 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
30 ok(tmp === "", "''.toString() = " + tmp);
31 tmp = "test".toString();
32 ok(tmp === "test", "''.toString() = " + tmp);
33 tmp = "test".toString(3);
34 ok(tmp === "test", "''.toString(3) = " + tmp);
37 ok(tmp === "", "''.valueOf() = " + tmp);
38 tmp = "test".valueOf();
39 ok(tmp === "test", "''.valueOf() = " + tmp);
40 tmp = "test".valueOf(3);
41 ok(tmp === "test", "''.valueOf(3) = " + tmp);
43 tmp = "abc".charAt(0);
44 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
45 tmp = "abc".charAt(1);
46 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
47 tmp = "abc".charAt(2);
48 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
49 tmp = "abc".charAt(3);
50 ok(tmp === "", "'abc',charAt(3) = " + tmp);
51 tmp = "abc".charAt(4);
52 ok(tmp === "", "'abc',charAt(4) = " + tmp);
54 ok(tmp === "a", "'abc',charAt() = " + tmp);
55 tmp = "abc".charAt(-1);
56 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
57 tmp = "abc".charAt(0,2);
58 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
60 tmp = "abcd".substring(1,3);
61 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
62 tmp = "abcd".substring(-1,3);
63 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
64 tmp = "abcd".substring(1,6);
65 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
66 tmp = "abcd".substring(3,1);
67 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
68 tmp = "abcd".substring(2,2);
69 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
70 tmp = "abcd".substring(true,"3");
71 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
72 tmp = "abcd".substring(1,3,2);
73 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
74 tmp = "abcd".substring();
75 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
77 tmp = "abcd".slice(1,3);
78 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
79 tmp = "abcd".slice(1,-1);
80 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
81 tmp = "abcd".slice(-3,3);
82 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
83 tmp = "abcd".slice(-6,3);
84 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
85 tmp = "abcd".slice(3,1);
86 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
87 tmp = "abcd".slice(true,3);
88 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
90 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
91 tmp = "abcd".slice(1);
92 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
94 var arr = new Array();
95 ok(typeof(arr) === "object", "arr () is not object");
96 ok((arr.length === 0), "arr.length is not 0");
97 ok(arr["0"] === undefined, "arr[0] is not undefined");
99 var arr = new Array(1, 2, "test");
100 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
101 ok((arr.length === 3), "arr.length is not 3");
102 ok(arr["0"] === 1, "arr[0] is not 1");
103 ok(arr["1"] === 2, "arr[1] is not 2");
104 ok(arr["2"] === "test", "arr[2] is not \"test\"");
107 ok((arr.length === 8), "arr.length is not 8");
110 ok(tmp === "", "'' + [] = " + tmp);
112 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
114 var arr = new Array(6);
115 ok(typeof(arr) === "object", "arr (6) is not object");
116 ok((arr.length === 6), "arr.length is not 6");
117 ok(arr["0"] === undefined, "arr[0] is not undefined");
119 ok(arr.push() === 6, "arr.push() !== 6");
120 ok(arr.push(1) === 7, "arr.push(1) !== 7");
121 ok(arr[6] === 1, "arr[6] != 1");
122 ok(arr.length === 7, "arr.length != 10");
123 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
124 ok(arr[8] === "b", "arr[8] != 'b'");
125 ok(arr.length === 10, "arr.length != 10");
127 arr = [1,2,null,false,undefined,,"a"];
130 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
132 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
133 tmp = arr.join(";","test");
134 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
136 ok(tmp === "12falsea", "arr.join('') = " + tmp);
138 tmp = arr.toString();
139 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
140 tmp = arr.toString("test");
141 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
143 arr = [5,true,2,-1,3,false,"2.5"];
144 tmp = arr.sort(function(x,y) { return y-x; });
145 ok(tmp === arr, "tmp !== arr");
146 tmp = [5,3,"2.5",2,true,false,-1];
147 for(var i=0; i < arr.length; i++)
148 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
150 arr = [5,false,2,0,"abc",3,"a",-1];
152 ok(tmp === arr, "tmp !== arr");
153 tmp = [-1,0,2,3,5,"a","abc",false];
154 for(var i=0; i < arr.length; i++)
155 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
157 arr = ["a", "b", "ab"];
158 tmp = ["a", "ab", "b"];
159 ok(arr.sort() === arr, "arr.sort() !== arr");
160 for(var i=0; i < arr.length; i++)
161 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
163 var num = new Number(6);
165 tmp = arr.concat(3, [4,5], num);
166 ok(tmp !== arr, "tmp === arr");
167 for(var i=0; i<6; i++)
168 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
169 ok(tmp[6] === num, "tmp[6] !== num");
170 ok(tmp.length === 7, "tmp.length = " + tmp.length);
173 ok(arr.length === 0, "arr.length = " + arr.lrngth);
176 tmp = arr.concat([2]);
177 ok(tmp.length === 3, "tmp.length = " + tmp.length);
178 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
180 var num = new Number(2);
181 ok(num.toString() === "2", "num(2).toString !== 2");
182 var num = new Number();
183 ok(num.toString() === "0", "num().toString !== 0");
185 ok(Number() === 0, "Number() = " + Number());
186 ok(Number(false) === 0, "Number(false) = " + Number(false));
187 ok(Number("43") === 43, "Number('43') = " + Number("43"));