* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma / Types / 8.4.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /**
40    File Name:          8.4.js
41    ECMA Section:       The String type
42    Description:
43
44    The String type is the set of all finite ordered sequences of zero or more
45    Unicode characters. Each character is regarded as occupying a position
46    within the sequence. These positions are identified by nonnegative
47    integers. The leftmost character (if any) is at position 0, the next
48    character (if any) at position 1, and so on. The length of a string is the
49    number of distinct positions within it. The empty string has length zero
50    and therefore contains no characters.
51
52    Author:             christine@netscape.com
53    Date:               12 november 1997
54 */
55
56 var SECTION = "8.4";
57 var VERSION = "ECMA_1";
58 startTest();
59 var TITLE   = "The String type";
60
61 writeHeaderToLog( SECTION + " "+ TITLE);
62
63 new TestCase( SECTION,
64               "var s = ''; s.length",
65               0,
66               eval("var s = ''; s.length") );
67
68 new TestCase( SECTION,
69               "var s = ''; s.charAt(0)",
70               "",
71               eval("var s = ''; s.charAt(0)") );
72
73
74 for ( var i = 0x0041, TEST_STRING = "", EXPECT_STRING = ""; i < 0x007B; i++ ) {
75   TEST_STRING += ("\\u"+ DecimalToHexString( i ) );
76   EXPECT_STRING += String.fromCharCode(i);
77 }
78
79 new TestCase( SECTION,
80               "var s = '" + TEST_STRING+ "'; s",
81               EXPECT_STRING,
82               eval("var s = '" + TEST_STRING+ "'; s") );
83
84 new TestCase( SECTION,
85               "var s = '" + TEST_STRING+ "'; s.length",
86               0x007B-0x0041,
87               eval("var s = '" + TEST_STRING+ "'; s.length") );
88
89 test();
90
91 function DecimalToHexString( n ) {
92   n = Number( n );
93   var h = "";
94
95   for ( var i = 3; i >= 0; i-- ) {
96     if ( n >= Math.pow(16, i) ){
97       var t = Math.floor( n  / Math.pow(16, i));
98       n -= t * Math.pow(16, i);
99       if ( t >= 10 ) {
100         if ( t == 10 ) {
101           h += "A";
102         }
103         if ( t == 11 ) {
104           h += "B";
105         }
106         if ( t == 12 ) {
107           h += "C";
108         }
109         if ( t == 13 ) {
110           h += "D";
111         }
112         if ( t == 14 ) {
113           h += "E";
114         }
115         if ( t == 15 ) {
116           h += "F";
117         }
118       } else {
119         h += String( t );
120       }
121     } else {
122       h += "0";
123     }
124   }
125
126   return h;
127 }
128