js/src/tests/ecma/String/15.5.4.5-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.5-3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     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-3.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-3";
    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 = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
    1.48 +
    1.49 +
    1.50 +var foo = new MyObject('hello');
    1.51 +
    1.52 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(0)", 0x0068, foo.charCodeAt(0)  );
    1.53 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(1)", 0x0065, foo.charCodeAt(1)  );
    1.54 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(2)", 0x006c, foo.charCodeAt(2)  );
    1.55 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(3)", 0x006c, foo.charCodeAt(3)  );
    1.56 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(4)", 0x006f, foo.charCodeAt(4)  );
    1.57 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(-1)", Number.NaN,  foo.charCodeAt(-1)  );
    1.58 +new TestCase( SECTION, "var foo = new MyObject('hello');foo.charCodeAt(5)", Number.NaN,  foo.charCodeAt(5)  );
    1.59 +
    1.60 +var boo = new MyObject(true);
    1.61 +
    1.62 +new TestCase( SECTION, "var boo = new MyObject(true);boo.charCodeAt(0)", 0x0074, boo.charCodeAt(0)  );
    1.63 +new TestCase( SECTION, "var boo = new MyObject(true);boo.charCodeAt(1)", 0x0072, boo.charCodeAt(1)  );
    1.64 +new TestCase( SECTION, "var boo = new MyObject(true);boo.charCodeAt(2)", 0x0075, boo.charCodeAt(2)  );
    1.65 +new TestCase( SECTION, "var boo = new MyObject(true);boo.charCodeAt(3)", 0x0065, boo.charCodeAt(3)  );
    1.66 +
    1.67 +var noo = new MyObject( Math.PI );
    1.68 +
    1.69 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(0)", 0x0033, noo.charCodeAt(0)  );
    1.70 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(1)", 0x002E, noo.charCodeAt(1)  );
    1.71 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(2)", 0x0031, noo.charCodeAt(2)  );
    1.72 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(3)", 0x0034, noo.charCodeAt(3)  );
    1.73 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(4)", 0x0031, noo.charCodeAt(4)  );
    1.74 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(5)", 0x0035, noo.charCodeAt(5)  );
    1.75 +new TestCase( SECTION, "var noo = new MyObject(Math.PI);noo.charCodeAt(6)", 0x0039, noo.charCodeAt(6)  );
    1.76 +
    1.77 +var noo = new MyObject( null );
    1.78 +
    1.79 +new TestCase( SECTION, "var noo = new MyObject(null);noo.charCodeAt(0)", 0x006E, noo.charCodeAt(0)  );
    1.80 +new TestCase( SECTION, "var noo = new MyObject(null);noo.charCodeAt(1)", 0x0075, noo.charCodeAt(1)  );
    1.81 +new TestCase( SECTION, "var noo = new MyObject(null);noo.charCodeAt(2)", 0x006C, noo.charCodeAt(2)  );
    1.82 +new TestCase( SECTION, "var noo = new MyObject(null);noo.charCodeAt(3)", 0x006C, noo.charCodeAt(3)  );
    1.83 +new TestCase( SECTION, "var noo = new MyObject(null);noo.charCodeAt(4)", NaN, noo.charCodeAt(4)  );
    1.84 +
    1.85 +var noo = new MyObject( void 0 );
    1.86 +
    1.87 +new TestCase( SECTION, "var noo = new MyObject(void 0);noo.charCodeAt(0)", 0x0075, noo.charCodeAt(0)  );
    1.88 +new TestCase( SECTION, "var noo = new MyObject(void 0);noo.charCodeAt(1)", 0x006E, noo.charCodeAt(1)  );
    1.89 +new TestCase( SECTION, "var noo = new MyObject(void 0);noo.charCodeAt(2)", 0x0064, noo.charCodeAt(2)  );
    1.90 +new TestCase( SECTION, "var noo = new MyObject(void 0);noo.charCodeAt(3)", 0x0065, noo.charCodeAt(3)  );
    1.91 +new TestCase( SECTION, "var noo = new MyObject(void 0);noo.charCodeAt(4)", 0x0066, noo.charCodeAt(4)  );
    1.92 +
    1.93 +test();
    1.94 +
    1.95 +
    1.96 +function MyObject (v) {
    1.97 +  this.value      = v;
    1.98 +  this.toString   = new Function ( "return this.value +\"\"" );
    1.99 +  this.charCodeAt     = String.prototype.charCodeAt;
   1.100 +}

mercurial