js/src/tests/ecma/String/15.5.4.4-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/String/15.5.4.4-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          15.5.4.4-1.js
    1.12 +   ECMA Section:       15.5.4.4 String.prototype.charAt(pos)
    1.13 +   Description:        Returns a string containing the character at position
    1.14 +   pos in the string.  If there is no character at that
    1.15 +   string, the result is the empty string.  The result is
    1.16 +   a string value, not a String object.
    1.17 +
    1.18 +   When the charAt method is called with one argument,
    1.19 +   pos, the following steps are taken:
    1.20 +   1. Call ToString, with this value as its argument
    1.21 +   2. Call ToInteger pos
    1.22 +
    1.23 +   In this test, this is a String, pos is an integer, and
    1.24 +   all pos are in range.
    1.25 +
    1.26 +   Author:             christine@netscape.com
    1.27 +   Date:               2 october 1997
    1.28 +*/
    1.29 +var SECTION = "15.5.4.4-1";
    1.30 +var VERSION = "ECMA_1";
    1.31 +startTest();
    1.32 +var TITLE   = "String.prototype.charAt";
    1.33 +
    1.34 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.35 +
    1.36 +var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
    1.37 +
    1.38 +var item = 0;
    1.39 +var i;
    1.40 +
    1.41 +for (  i = 0x0020; i < 0x007e; i++, item++) {
    1.42 +  new TestCase( SECTION,
    1.43 +		"TEST_STRING.charAt("+item+")",
    1.44 +		String.fromCharCode( i ),
    1.45 +		TEST_STRING.charAt( item ) );
    1.46 +}
    1.47 +
    1.48 +for ( i = 0x0020; i < 0x007e; i++, item++) {
    1.49 +  new TestCase( SECTION,
    1.50 +		"TEST_STRING.charAt("+item+") == TEST_STRING.substring( "+item +", "+ (item+1) + ")",
    1.51 +		true,
    1.52 +		TEST_STRING.charAt( item )  == TEST_STRING.substring( item, item+1 )
    1.53 +    );
    1.54 +}
    1.55 +
    1.56 +new TestCase( SECTION,  "String.prototype.charAt.length",       1,  String.prototype.charAt.length );
    1.57 +
    1.58 +print( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" );
    1.59 +
    1.60 +test();
    1.61 +

mercurial