initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / String / 15.5.4.4-1.js
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:          15.5.4.4-1.js
24     ECMA Section:       15.5.4.4 String.prototype.charAt(pos)
25     Description:        Returns a string containing the character at position
26                         pos in the string.  If there is no character at that
27                         string, the result is the empty string.  The result is
28                         a string value, not a String object.
29
30                         When the charAt method is called with one argument,
31                         pos, the following steps are taken:
32                         1. Call ToString, with this value as its argument
33                         2. Call ToInteger pos
34
35                         In this test, this is a String, pos is an integer, and
36                         all pos are in range.
37
38     Author:             christine@netscape.com
39     Date:               2 october 1997
40 */
41     var SECTION = "15.5.4.4-1";
42     var VERSION = "ECMA_1";
43     startTest();
44     var TITLE   = "String.prototype.charAt";
45
46     writeHeaderToLog( SECTION + " "+ TITLE);
47
48     var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
49
50     var testcases = getTestCases();
51     test();
52
53 function getTestCases() {
54     var array = new Array();
55     var item = 0;
56
57     for (  i = 0x0020; i < 0x007e; i++, item++) {
58         array[item] = new TestCase( SECTION,
59                                 "TEST_STRING.charAt("+item+")",
60                                 String.fromCharCode( i ),
61                                 TEST_STRING.charAt( item ) );
62     }
63     for ( i = 0x0020; i < 0x007e; i++, item++) {
64         array[item] = new TestCase( SECTION,
65                                 "TEST_STRING.charAt("+item+") == TEST_STRING.substring( "+item +", "+ (item+1) + ")",
66                                 true,
67                                 TEST_STRING.charAt( item )  == TEST_STRING.substring( item, item+1 )
68                                 );
69     }
70     array[item++] = new TestCase( SECTION,  "String.prototype.charAt.length",       1,  String.prototype.charAt.length );
71
72     return array;
73 }
74 function test() {
75         writeLineToLog( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
76         for ( tc = 0; tc < testcases.length; tc++ ) {
77             testcases[tc].passed = writeTestCaseResult(
78                     testcases[tc].expect,
79                     testcases[tc].actual,
80                     testcases[tc].description +" = "+ testcases[tc].actual );
81
82             testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "
83         }
84         stopTest();
85
86     return ( testcases );
87 }