1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 15.5.2 The String Constructor
25 15.5.2.1 new String(value)
28 Description: When String is called as part of a new expression, it
29 is a constructor; it initializes the newly constructed
32 - The prototype property of the newly constructed
33 object is set to the original String prototype object,
34 the one that is the intial value of String.prototype
35 - The internal [[Class]] property of the object is "String"
36 - The value of the object is ToString(value).
37 - If no value is specified, its value is the empty string.
39 Author: christine@netscape.com
43 var SECTION = "15.5.2";
44 var VERSION = "ECMA_1";
46 var TITLE = "The String Constructor";
48 writeHeaderToLog( SECTION + " "+ TITLE);
50 var testcases = getTestCases();
53 function getTestCases() {
54 var array = new Array();
57 array[item++] = new TestCase( SECTION, "typeof new String('string primitive')", "object", typeof new String('string primitive') );
58 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String('string primitive'); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String('string primitive'); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
59 array[item++] = new TestCase( SECTION, "(new String('string primitive')).valueOf()", 'string primitive', (new String('string primitive')).valueOf() );
60 array[item++] = new TestCase( SECTION, "(new String('string primitive')).substring", String.prototype.substring, (new String('string primitive')).substring );
62 array[item++] = new TestCase( SECTION, "typeof new String(void 0)", "object", typeof new String(void 0) );
63 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(void 0); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(void 0); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
64 array[item++] = new TestCase( SECTION, "(new String(void 0)).valueOf()", "undefined", (new String(void 0)).valueOf() );
65 array[item++] = new TestCase( SECTION, "(new String(void 0)).toString", String.prototype.toString, (new String(void 0)).toString );
67 array[item++] = new TestCase( SECTION, "typeof new String(null)", "object", typeof new String(null) );
68 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(null); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(null); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
69 array[item++] = new TestCase( SECTION, "(new String(null)).valueOf()", "null", (new String(null)).valueOf() );
70 array[item++] = new TestCase( SECTION, "(new String(null)).valueOf", String.prototype.valueOf, (new String(null)).valueOf );
72 array[item++] = new TestCase( SECTION, "typeof new String(true)", "object", typeof new String(true) );
73 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(true); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(true); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
74 array[item++] = new TestCase( SECTION, "(new String(true)).valueOf()", "true", (new String(true)).valueOf() );
75 array[item++] = new TestCase( SECTION, "(new String(true)).charAt", String.prototype.charAt, (new String(true)).charAt );
77 array[item++] = new TestCase( SECTION, "typeof new String(false)", "object", typeof new String(false) );
78 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(false); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(false); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
79 array[item++] = new TestCase( SECTION, "(new String(false)).valueOf()", "false", (new String(false)).valueOf() );
80 array[item++] = new TestCase( SECTION, "(new String(false)).charCodeAt", String.prototype.charCodeAt, (new String(false)).charCodeAt );
82 array[item++] = new TestCase( SECTION, "typeof new String(new Boolean(true))", "object", typeof new String(new Boolean(true)) );
83 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(new Boolean(true)); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(new Boolean(true)); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
84 array[item++] = new TestCase( SECTION, "(new String(new Boolean(true))).valueOf()", "true", (new String(new Boolean(true))).valueOf() );
85 array[item++] = new TestCase( SECTION, "(new String(new Boolean(true))).indexOf", String.prototype.indexOf, (new String(new Boolean(true))).indexOf );
87 array[item++] = new TestCase( SECTION, "typeof new String()", "object", typeof new String() );
88 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
89 array[item++] = new TestCase( SECTION, "(new String()).valueOf()", '', (new String()).valueOf() );
90 array[item++] = new TestCase( SECTION, "(new String()).lastIndexOf", String.prototype.lastIndexOf, (new String()).lastIndexOf );
92 array[item++] = new TestCase( SECTION, "typeof new String('')", "object", typeof new String('') );
93 array[item++] = new TestCase( SECTION, "var TESTSTRING = new String(''); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()", "[object String]", eval("var TESTSTRING = new String(''); TESTSTRING.toString=Object.prototype.toString;TESTSTRING.toString()") );
94 array[item++] = new TestCase( SECTION, "(new String('')).valueOf()", '', (new String('')).valueOf() );
95 array[item++] = new TestCase( SECTION, "(new String('')).split", String.prototype.split, (new String('')).split );
101 for ( tc=0; tc < testcases.length; tc++ ) {
102 testcases[tc].passed = writeTestCaseResult(
103 testcases[tc].expect,
104 testcases[tc].actual,
105 testcases[tc].description +" = "+
106 testcases[tc].actual );
108 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
111 return ( testcases );