jscript: Added Number function implementation.
[wine/wine-kai.git] / dlls / jscript / tests / api.js
blobecc6da4c7a347ce6c0fe31c1a048708ff554944d
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
19 var tmp;
21 ok("".length === 0, "\"\".length = " + "".length);
22 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
23 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
24 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
26 tmp = "abc".charAt(0);
27 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
28 tmp = "abc".charAt(1);
29 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
30 tmp = "abc".charAt(2);
31 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
32 tmp = "abc".charAt(3);
33 ok(tmp === "", "'abc',charAt(3) = " + tmp);
34 tmp = "abc".charAt(4);
35 ok(tmp === "", "'abc',charAt(4) = " + tmp);
36 tmp = "abc".charAt();
37 ok(tmp === "a", "'abc',charAt() = " + tmp);
38 tmp = "abc".charAt(-1);
39 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
40 tmp = "abc".charAt(0,2);
41 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
43 var arr = new Array();
44 ok(typeof(arr) === "object", "arr () is not object");
45 ok((arr.length === 0), "arr.length is not 0");
46 ok(arr["0"] === undefined, "arr[0] is not undefined");
48 var arr = new Array(1, 2, "test");
49 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
50 ok((arr.length === 3), "arr.length is not 3");
51 ok(arr["0"] === 1, "arr[0] is not 1");
52 ok(arr["1"] === 2, "arr[1] is not 2");
53 ok(arr["2"] === "test", "arr[2] is not \"test\"");
55 arr["7"] = true;
56 ok((arr.length === 8), "arr.length is not 8");
58 var arr = new Array(6);
59 ok(typeof(arr) === "object", "arr (6) is not object");
60 ok((arr.length === 6), "arr.length is not 6");
61 ok(arr["0"] === undefined, "arr[0] is not undefined");
63 ok(arr.push() === 6, "arr.push() !== 6");
64 ok(arr.push(1) === 7, "arr.push(1) !== 7");
65 ok(arr[6] === 1, "arr[6] != 1");
66 ok(arr.length === 7, "arr.length != 10");
67 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
68 ok(arr[8] === "b", "arr[8] != 'b'");
69 ok(arr.length === 10, "arr.length != 10");
71 arr = [1,2,null,false,undefined,,"a"];
73 tmp = arr.join();
74 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
75 tmp = arr.join(";");
76 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
77 tmp = arr.join(";","test");
78 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
79 tmp = arr.join("");
80 ok(tmp === "12falsea", "arr.join('') = " + tmp);
82 tmp = arr.toString();
83 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
84 tmp = arr.toString("test");
85 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
87 var num = new Number(2);
88 ok(num.toString() === "2", "num(2).toString !== 2");
89 var num = new Number();
90 ok(num.toString() === "0", "num().toString !== 0");
92 ok(Number() === 0, "Number() = " + Number());
93 ok(Number(false) === 0, "Number(false) = " + Number(false));
94 ok(Number("43") === 43, "Number('43') = " + Number("43"));
96 reportSuccess();