/* * Copyright 2008 Jacek Caban for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ var tmp; tmp = "" + new Object(); ok(tmp === "[object Object]", "'' + new Object() = " + tmp); ok("".length === 0, "\"\".length = " + "".length); ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length); ok("abc".length === 3, "\"abc\".length = " + "abc".length); ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length); tmp = "abc".charAt(0); ok(tmp === "a", "'abc',charAt(0) = " + tmp); tmp = "abc".charAt(1); ok(tmp === "b", "'abc',charAt(1) = " + tmp); tmp = "abc".charAt(2); ok(tmp === "c", "'abc',charAt(2) = " + tmp); tmp = "abc".charAt(3); ok(tmp === "", "'abc',charAt(3) = " + tmp); tmp = "abc".charAt(4); ok(tmp === "", "'abc',charAt(4) = " + tmp); tmp = "abc".charAt(); ok(tmp === "a", "'abc',charAt() = " + tmp); tmp = "abc".charAt(-1); ok(tmp === "", "'abc',charAt(-1) = " + tmp); tmp = "abc".charAt(0,2); ok(tmp === "a", "'abc',charAt(0.2) = " + tmp); var arr = new Array(); ok(typeof(arr) === "object", "arr () is not object"); ok((arr.length === 0), "arr.length is not 0"); ok(arr["0"] === undefined, "arr[0] is not undefined"); var arr = new Array(1, 2, "test"); ok(typeof(arr) === "object", "arr (1,2,test) is not object"); ok((arr.length === 3), "arr.length is not 3"); ok(arr["0"] === 1, "arr[0] is not 1"); ok(arr["1"] === 2, "arr[1] is not 2"); ok(arr["2"] === "test", "arr[2] is not \"test\""); arr["7"] = true; ok((arr.length === 8), "arr.length is not 8"); tmp = "" + []; ok(tmp === "", "'' + [] = " + tmp); tmp = "" + [1,true]; ok(tmp === "1,true", "'' + [1,true] = " + tmp); var arr = new Array(6); ok(typeof(arr) === "object", "arr (6) is not object"); ok((arr.length === 6), "arr.length is not 6"); ok(arr["0"] === undefined, "arr[0] is not undefined"); ok(arr.push() === 6, "arr.push() !== 6"); ok(arr.push(1) === 7, "arr.push(1) !== 7"); ok(arr[6] === 1, "arr[6] != 1"); ok(arr.length === 7, "arr.length != 10"); ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10"); ok(arr[8] === "b", "arr[8] != 'b'"); ok(arr.length === 10, "arr.length != 10"); arr = [1,2,null,false,undefined,,"a"]; tmp = arr.join(); ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp); tmp = arr.join(";"); ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp); tmp = arr.join(";","test"); ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp); tmp = arr.join(""); ok(tmp === "12falsea", "arr.join('') = " + tmp); tmp = arr.toString(); ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp); tmp = arr.toString("test"); ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp); arr = [5,true,2,-1,3,false,"2.5"]; tmp = arr.sort(function(x,y) { return y-x; }); ok(tmp === arr, "tmp !== arr"); tmp = [5,3,"2.5",2,true,false,-1]; for(var i=0; i < arr.length; i++) ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); arr = [5,false,2,0,"abc",3,"a",-1]; tmp = arr.sort(); ok(tmp === arr, "tmp !== arr"); tmp = [-1,0,2,3,5,"a","abc",false]; for(var i=0; i < arr.length; i++) ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); arr = ["a", "b", "ab"]; tmp = ["a", "ab", "b"]; ok(arr.sort() === arr, "arr.sort() !== arr"); for(var i=0; i < arr.length; i++) ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); var num = new Number(6); arr = [0,1,2]; tmp = arr.concat(3, [4,5], num); ok(tmp !== arr, "tmp === arr"); for(var i=0; i<6; i++) ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]); ok(tmp[6] === num, "tmp[6] !== num"); ok(tmp.length === 7, "tmp.length = " + tmp.length); arr = [].concat(); ok(arr.length === 0, "arr.length = " + arr.lrngth); arr = [1,]; tmp = arr.concat([2]); ok(tmp.length === 3, "tmp.length = " + tmp.length); ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]); var num = new Number(2); ok(num.toString() === "2", "num(2).toString !== 2"); var num = new Number(); ok(num.toString() === "0", "num().toString !== 0"); ok(Number() === 0, "Number() = " + Number()); ok(Number(false) === 0, "Number(false) = " + Number(false)); ok(Number("43") === 43, "Number('43') = " + Number("43")); reportSuccess();