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: The String type
27 The String type is the set of all finite ordered sequences of zero or more
28 Unicode characters. Each character is regarded as occupying a position
29 within the sequence. These positions are identified by nonnegative
30 integers. The leftmost character (if any) is at position 0, the next
31 character (if any) at position 1, and so on. The length of a string is the
32 number of distinct positions within it. The empty string has length zero
33 and therefore contains no characters.
35 Author: christine@netscape.com
36 Date: 12 november 1997
40 var VERSION = "ECMA_1";
42 var TITLE = "The String type";
44 writeHeaderToLog( SECTION + " "+ TITLE);
46 var testcases = new Array();
48 testcases[tc++] = new TestCase( SECTION,
49 "var s = ''; s.length",
51 eval("var s = ''; s.length") );
53 testcases[tc++] = new TestCase( SECTION,
54 "var s = ''; s.charAt(0)",
56 eval("var s = ''; s.charAt(0)") );
59 for ( var i = 0x0041, TEST_STRING = "", EXPECT_STRING = ""; i < 0x007B; i++ ) {
60 TEST_STRING += ("\\u"+ DecimalToHexString( i ) );
61 EXPECT_STRING += String.fromCharCode(i);
64 testcases[tc++] = new TestCase( SECTION,
65 "var s = '" + TEST_STRING+ "'; s",
67 eval("var s = '" + TEST_STRING+ "'; s") );
69 testcases[tc++] = new TestCase( SECTION,
70 "var s = '" + TEST_STRING+ "'; s.length",
72 eval("var s = '" + TEST_STRING+ "'; s.length") );
75 function DecimalToHexString( n ) {
79 for ( var i = 3; i >= 0; i-- ) {
80 if ( n >= Math.pow(16, i) ){
81 var t = Math.floor( n / Math.pow(16, i));
82 n -= t * Math.pow(16, i);
114 for ( tc=0; tc < testcases.length; tc++ ) {
115 testcases[tc].passed = writeTestCaseResult(
116 testcases[tc].expect,
117 testcases[tc].actual,
118 testcases[tc].description +" = "+
119 testcases[tc].actual );
121 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
124 return ( testcases );