1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
File Name: 15.5.4.4-1.js
ECMA Section: 15.5.4.4 String.prototype.charAt(pos)
Description: Returns a string containing the character at position
pos in the string. If there is no character at that
string, the result is the empty string. The result is
a string value, not a String object.
When the charAt method is called with one argument,
pos, the following steps are taken:
1. Call ToString, with this value as its argument
2. Call ToInteger pos
In this test, this is a String, pos is an integer, and
all pos are in range.
Author: christine@netscape.com
Date: 2 october 1997
*/
var SECTION = "15.5.4.4-1";
var VERSION = "ECMA_1";
startTest();
var TITLE = "String.prototype.charAt";
writeHeaderToLog( SECTION + " "+ TITLE);
var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
var item = 0;
var i;
for ( i = 0x0020; i < 0x007e; i++, item++) {
new TestCase( SECTION,
"TEST_STRING.charAt("+item+")",
String.fromCharCode( i ),
TEST_STRING.charAt( item ) );
}
for ( i = 0x0020; i < 0x007e; i++, item++) {
new TestCase( SECTION,
"TEST_STRING.charAt("+item+") == TEST_STRING.substring( "+item +", "+ (item+1) + ")",
true,
TEST_STRING.charAt( item ) == TEST_STRING.substring( item, item+1 )
);
}
new TestCase( SECTION, "String.prototype.charAt.length", 1, String.prototype.charAt.length );
print( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
test();
|