Debian Codegraph @

rhino/testsrc/tests/ecma/String/15.5.4.4-3.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.5.4.4-3.js';
7
8 /**
9 File Name: 15.5.4.4-3.js
10 ECMA Section: 15.5.4.4 String.prototype.charAt(pos)
11 Description: Returns a string containing the character at position
12 pos in the string. If there is no character at that
13 string, the result is the empty string. The result is
14 a string value, not a String object.
15
16 When the charAt method is called with one argument,
17 pos, the following steps are taken:
18 1. Call ToString, with this value as its argument
19 2. Call ToInteger pos
20 3. Compute the number of characters in Result(1)
21 4. If Result(2) is less than 0 is or not less than
22 Result(3), return the empty string
23 5. Return a string of length 1 containing one character
24 from result (1), the character at position Result(2).
25
26 Note that the charAt function is intentionally generic;
27 it does not require that its this value be a String
28 object. Therefore it can be transferred to other kinds
29 of objects for use as a method.
30
31 This tests assiging charAt to a user-defined function.
32
33 Author: [email protected]
34 Date: 2 october 1997
35 */
36 var SECTION = "15.5.4.4-3";
37 var VERSION = "ECMA_1";
38 startTest();
39 var TITLE = "String.prototype.charAt";
40
41 writeHeaderToLog( SECTION + " "+ TITLE);
42
43 var foo = new MyObject('hello');
44
45
46 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "h", foo.charAt(0) );
47 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "e", foo.charAt(1) );
48 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "l", foo.charAt(2) );
49 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "l", foo.charAt(3) );
50 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "o", foo.charAt(4) );
51 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "", foo.charAt(-1) );
52 new TestCase( SECTION, "var foo = new MyObject('hello'); ", "", foo.charAt(5) );
53
54 var boo = new MyObject(true);
55
56 new TestCase( SECTION, "var boo = new MyObject(true); ", "t", boo.charAt(0) );
57 new TestCase( SECTION, "var boo = new MyObject(true); ", "r", boo.charAt(1) );
58 new TestCase( SECTION, "var boo = new MyObject(true); ", "u", boo.charAt(2) );
59 new TestCase( SECTION, "var boo = new MyObject(true); ", "e", boo.charAt(3) );
60
61 var noo = new MyObject( Math.PI );
62
63 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "3", noo.charAt(0) );
64 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", ".", noo.charAt(1) );
65 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "1", noo.charAt(2) );
66 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "4", noo.charAt(3) );
67 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "1", noo.charAt(4) );
68 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "5", noo.charAt(5) );
69 new TestCase( SECTION, "var noo = new MyObject(Math.PI); ", "9", noo.charAt(6) );
70
71 test();
72
73 function MyObject (v) {
74 this.value = v;
75 this.toString = new Function( "return this.value +'';" );
76 this.valueOf = new Function( "return this.value" );
77 this.charAt = String.prototype.charAt;
78 }
79