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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          8.4.js
24    ECMA Section:       The String type
25    Description:
26
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.
34
35    Author:             christine@netscape.com
36    Date:               12 november 1997
37*/
38
39    var SECTION = "8.4";
40    var VERSION = "ECMA_1";
41    startTest();
42    var TITLE   = "The String type";
43
44    writeHeaderToLog( SECTION + " "+ TITLE);
45
46    var testcases = new Array();
47
48    testcases[tc++] = new TestCase( SECTION,
49                                    "var s = ''; s.length",
50                                    0,
51                                    eval("var s = ''; s.length") );
52
53    testcases[tc++] = new TestCase( SECTION,
54                                    "var s = ''; s.charAt(0)",
55                                    "",
56                                    eval("var s = ''; s.charAt(0)") );
57
58
59    for ( var i = 0x0041, TEST_STRING = "", EXPECT_STRING = ""; i < 0x007B; i++ ) {
60        TEST_STRING += ("\\u"+ DecimalToHexString( i ) );
61        EXPECT_STRING += String.fromCharCode(i);
62    }
63
64    testcases[tc++] = new TestCase( SECTION,
65                                    "var s = '" + TEST_STRING+ "'; s",
66                                    EXPECT_STRING,
67                                    eval("var s = '" + TEST_STRING+ "'; s") );
68
69    testcases[tc++] = new TestCase( SECTION,
70                                    "var s = '" + TEST_STRING+ "'; s.length",
71                                    0x007B-0x0041,
72                                    eval("var s = '" + TEST_STRING+ "'; s.length") );
73
74    test();
75function DecimalToHexString( n ) {
76    n = Number( n );
77    var h = "";
78
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);
83            if ( t >= 10 ) {
84                if ( t == 10 ) {
85                    h += "A";
86                }
87                if ( t == 11 ) {
88                    h += "B";
89                }
90                if ( t == 12 ) {
91                    h += "C";
92                }
93                if ( t == 13 ) {
94                    h += "D";
95                }
96                if ( t == 14 ) {
97                    h += "E";
98                }
99                if ( t == 15 ) {
100                    h += "F";
101                }
102            } else {
103                h += String( t );
104            }
105        } else {
106            h += "0";
107        }
108    }
109
110    return h;
111}
112
113function test() {
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 );
120
121        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
122    }
123    stopTest();
124    return ( testcases );
125}
126