js/src/tests/ecma/String/15.5.4.5-5.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.5-5.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     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.5.1.js
    1.12 +   ECMA Section:       15.5.4.5 String.prototype.charCodeAt(pos)
    1.13 +   Description:        Returns a number (a nonnegative integer less than 2^16)
    1.14 +   representing the Unicode encoding of the character at
    1.15 +   position pos in this string.  If there is no character
    1.16 +   at that position, the number is NaN.
    1.17 +
    1.18 +   When the charCodeAt method is called with one argument
    1.19 +   pos, the following steps are taken:
    1.20 +   1. Call ToString, giving it the theis value as its
    1.21 +   argument
    1.22 +   2. Call ToInteger(pos)
    1.23 +   3. Compute the number of characters in result(1).
    1.24 +   4. If Result(2) is less than 0 or is not less than
    1.25 +   Result(3), return NaN.
    1.26 +   5. Return a value of Number type, of positive sign, whose
    1.27 +   magnitude is the Unicode encoding of one character
    1.28 +   from result 1, namely the characer at position Result
    1.29 +   (2), where the first character in Result(1) is
    1.30 +   considered to be at position 0.
    1.31 +
    1.32 +   Note that the charCodeAt function is intentionally
    1.33 +   generic; it does not require that its this value be a
    1.34 +   String object.  Therefore it can be transferred to other
    1.35 +   kinds of objects for use as a method.
    1.36 +
    1.37 +   Author:             christine@netscape.com
    1.38 +   Date:               2 october 1997
    1.39 +*/
    1.40 +var SECTION = "15.5.4.5-5";
    1.41 +var VERSION = "ECMA_1";
    1.42 +startTest();
    1.43 +var TITLE   = "String.prototype.charCodeAt";
    1.44 +
    1.45 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.46 +
    1.47 +var TEST_STRING = "";
    1.48 +
    1.49 +for ( var i = 0x0000; i < 255; i++ ) {
    1.50 +  TEST_STRING += String.fromCharCode( i );
    1.51 +}
    1.52 +
    1.53 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(0)", 0x0074,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(0)") );
    1.54 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(1)", 0x0072,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(1)") );
    1.55 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(2)", 0x0075,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(2)") );
    1.56 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(3)", 0x0065,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(3)") );
    1.57 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(4)", Number.NaN,     eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(4)") );
    1.58 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(-1)", Number.NaN,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(-1)") );
    1.59 +
    1.60 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(true)",  0x0072,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(true)") );
    1.61 +new TestCase( SECTION,     "x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(false)", 0x0074,    eval("x = new Boolean(true); x.charCodeAt=String.prototype.charCodeAt;x.charCodeAt(false)") );
    1.62 +
    1.63 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(0)",    Number.NaN,     eval("x=new String();x.charCodeAt(0)") );
    1.64 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(1)",    Number.NaN,     eval("x=new String();x.charCodeAt(1)") );
    1.65 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(-1)",   Number.NaN,     eval("x=new String();x.charCodeAt(-1)") );
    1.66 +
    1.67 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(NaN)",  Number.NaN,     eval("x=new String();x.charCodeAt(Number.NaN)") );
    1.68 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(Number.POSITIVE_INFINITY)",   Number.NaN,     eval("x=new String();x.charCodeAt(Number.POSITIVE_INFINITY)") );
    1.69 +new TestCase( SECTION,     "x = new String(); x.charCodeAt(Number.NEGATIVE_INFINITY)",   Number.NaN,     eval("x=new String();x.charCodeAt(Number.NEGATIVE_INFINITY)") );
    1.70 +
    1.71 +for ( var j = 0; j < 255; j++ ) {
    1.72 +  new TestCase( SECTION,  "TEST_STRING.charCodeAt("+j+")",    j,     TEST_STRING.charCodeAt(j) );
    1.73 +}
    1.74 +
    1.75 +test();

mercurial