js/src/tests/ecma/String/15.5.4.4-3.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-3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     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-3.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 +   3. Compute the number of characters  in Result(1)
    1.23 +   4. If Result(2) is less than 0 is or not less than
    1.24 +   Result(3), return the empty string
    1.25 +   5. Return a string of length 1 containing one character
    1.26 +   from result (1), the character at position Result(2).
    1.27 +
    1.28 +   Note that the charAt function is intentionally generic;
    1.29 +   it does not require that its this value be a String
    1.30 +   object.  Therefore it can be transferred to other kinds
    1.31 +   of objects for use as a method.
    1.32 +
    1.33 +   This tests assiging charAt to a user-defined function.
    1.34 +
    1.35 +   Author:             christine@netscape.com
    1.36 +   Date:               2 october 1997
    1.37 +*/
    1.38 +var SECTION = "15.5.4.4-3";
    1.39 +var VERSION = "ECMA_1";
    1.40 +startTest();
    1.41 +var TITLE   = "String.prototype.charAt";
    1.42 +
    1.43 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.44 +
    1.45 +var foo = new MyObject('hello');
    1.46 +
    1.47 +
    1.48 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "h", foo.charAt(0)  );
    1.49 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "e", foo.charAt(1)  );
    1.50 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "l", foo.charAt(2)  );
    1.51 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "l", foo.charAt(3)  );
    1.52 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "o", foo.charAt(4)  );
    1.53 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "",  foo.charAt(-1)  );
    1.54 +new TestCase( SECTION, "var foo = new MyObject('hello'); ", "",  foo.charAt(5)  );
    1.55 +
    1.56 +var boo = new MyObject(true);
    1.57 +
    1.58 +new TestCase( SECTION, "var boo = new MyObject(true); ", "t", boo.charAt(0)  );
    1.59 +new TestCase( SECTION, "var boo = new MyObject(true); ", "r", boo.charAt(1)  );
    1.60 +new TestCase( SECTION, "var boo = new MyObject(true); ", "u", boo.charAt(2)  );
    1.61 +new TestCase( SECTION, "var boo = new MyObject(true); ", "e", boo.charAt(3)  );
    1.62 +
    1.63 +var noo = new MyObject( Math.PI );
    1.64 +
    1.65 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "3", noo.charAt(0)  );
    1.66 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", ".", noo.charAt(1)  );
    1.67 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "1", noo.charAt(2)  );
    1.68 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "4", noo.charAt(3)  );
    1.69 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "1", noo.charAt(4)  );
    1.70 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "5", noo.charAt(5)  );
    1.71 +new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "9", noo.charAt(6)  );
    1.72 +
    1.73 +test();
    1.74 +
    1.75 +function MyObject (v) {
    1.76 +  this.value      = v;
    1.77 +  this.toString   = new Function( "return this.value +'';" );
    1.78 +  this.valueOf    = new Function( "return this.value" );
    1.79 +  this.charAt     = String.prototype.charAt;
    1.80 +}
    1.81 +

mercurial