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
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.
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
35 In this test, this is a String, pos is an integer, and
38 Author: christine@netscape.com
41 var SECTION = "15.5.4.4-1";
42 var VERSION = "ECMA_1";
44 var TITLE = "String.prototype.charAt";
46 writeHeaderToLog( SECTION + " "+ TITLE);
48 var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
50 var testcases = getTestCases();
53 function getTestCases() {
54 var array = new Array();
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 ) );
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) + ")",
67 TEST_STRING.charAt( item ) == TEST_STRING.substring( item, item+1 )
70 array[item++] = new TestCase( SECTION, "String.prototype.charAt.length", 1, String.prototype.charAt.length );
75 writeLineToLog( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
76 for ( tc = 0; tc < testcases.length; tc++ ) {
77 testcases[tc].passed = writeTestCaseResult(
80 testcases[tc].description +" = "+ testcases[tc].actual );
82 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "