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);
29 tmp = "abc".charAt(0);
30 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
31 tmp = "abc".charAt(1);
32 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
33 tmp = "abc".charAt(2);
34 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
35 tmp = "abc".charAt(3);
36 ok(tmp === "", "'abc',charAt(3) = " + tmp);
37 tmp = "abc".charAt(4);
38 ok(tmp === "", "'abc',charAt(4) = " + tmp);
40 ok(tmp === "a", "'abc',charAt() = " + tmp);
41 tmp = "abc".charAt(-1);
42 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
43 tmp = "abc".charAt(0,2);
44 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
46 var arr = new Array();
47 ok(typeof(arr) === "object", "arr () is not object");
48 ok((arr.length === 0), "arr.length is not 0");
49 ok(arr["0"] === undefined, "arr[0] is not undefined");
51 var arr = new Array(1, 2, "test");
52 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
53 ok((arr.length === 3), "arr.length is not 3");
54 ok(arr["0"] === 1, "arr[0] is not 1");
55 ok(arr["1"] === 2, "arr[1] is not 2");
56 ok(arr["2"] === "test", "arr[2] is not \"test\"");
59 ok((arr.length === 8), "arr.length is not 8");
61 var arr = new Array(6);
62 ok(typeof(arr) === "object", "arr (6) is not object");
63 ok((arr.length === 6), "arr.length is not 6");
64 ok(arr["0"] === undefined, "arr[0] is not undefined");
66 ok(arr.push() === 6, "arr.push() !== 6");
67 ok(arr.push(1) === 7, "arr.push(1) !== 7");
68 ok(arr[6] === 1, "arr[6] != 1");
69 ok(arr.length === 7, "arr.length != 10");
70 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
71 ok(arr[8] === "b", "arr[8] != 'b'");
72 ok(arr.length === 10, "arr.length != 10");
74 arr = [1,2,null,false,undefined,,"a"];
77 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
79 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
80 tmp = arr.join(";","test");
81 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
83 ok(tmp === "12falsea", "arr.join('') = " + tmp);
86 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
87 tmp = arr.toString("test");
88 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
90 arr = [5,true,2,-1,3,false,"2.5"];
91 tmp = arr.sort(function(x,y) { return y-x; });
92 ok(tmp === arr, "tmp !== arr");
93 tmp = [5,3,"2.5",2,true,false,-1];
94 for(var i=0; i < arr.length; i++)
95 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
97 arr = [5,false,2,0,"abc",3,"a",-1];
99 ok(tmp === arr, "tmp !== arr");
100 tmp = [-1,0,2,3,5,"a","abc",false];
101 for(var i=0; i < arr.length; i++)
102 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
104 arr = ["a", "b", "ab"];
105 tmp = ["a", "ab", "b"];
106 ok(arr.sort() === arr, "arr.sort() !== arr");
107 for(var i=0; i < arr.length; i++)
108 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
110 var num = new Number(6);
112 tmp = arr.concat(3, [4,5], num);
113 ok(tmp !== arr, "tmp === arr");
114 for(var i=0; i<6; i++)
115 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
116 ok(tmp[6] === num, "tmp[6] !== num");
117 ok(tmp.length === 7, "tmp.length = " + tmp.length);
120 ok(arr.length === 0, "arr.length = " + arr.lrngth);
123 tmp = arr.concat([2]);
124 ok(tmp.length === 3, "tmp.length = " + tmp.length);
125 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
127 var num = new Number(2);
128 ok(num.toString() === "2", "num(2).toString !== 2");
129 var num = new Number();
130 ok(num.toString() === "0", "num().toString !== 0");
132 ok(Number() === 0, "Number() = " + Number());
133 ok(Number(false) === 0, "Number(false) = " + Number(false));
134 ok(Number("43") === 43, "Number('43') = " + Number("43"));