]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: 15.5.4.5.1.js | |
24 | ECMA Section: 15.5.4.5 String.prototype.charCodeAt(pos) | |
25 | Description: Returns a number (a nonnegative integer less than 2^16) | |
26 | representing the Unicode encoding of the character at | |
27 | position pos in this string. If there is no character | |
28 | at that position, the number is NaN. | |
29 | ||
30 | When the charCodeAt method is called with one argument | |
31 | pos, the following steps are taken: | |
32 | 1. Call ToString, giving it the theis value as its | |
33 | argument | |
34 | 2. Call ToInteger(pos) | |
35 | 3. Compute the number of characters in result(1). | |
36 | 4. If Result(2) is less than 0 or is not less than | |
37 | Result(3), return NaN. | |
38 | 5. Return a value of Number type, of positive sign, whose | |
39 | magnitude is the Unicode encoding of one character | |
40 | from result 1, namely the characer at position Result | |
41 | (2), where the first character in Result(1) is | |
42 | considered to be at position 0. | |
43 | ||
44 | Note that the charCodeAt funciton is intentionally | |
45 | generic; it does not require that its this value be a | |
46 | String object. Therefore it can be transferred to other | |
47 | kinds of objects for use as a method. | |
48 | ||
49 | Author: christine@netscape.com | |
50 | Date: 2 october 1997 | |
51 | */ | |
52 | var SECTION = "15.5.4.5-1"; | |
53 | var VERSION = "ECMA_1"; | |
54 | startTest(); | |
55 | var TITLE = "String.prototype.charCodeAt"; | |
56 | ||
57 | writeHeaderToLog( SECTION + " "+ TITLE); | |
58 | ||
59 | var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ); | |
60 | ||
61 | var testcases = getTestCases(); | |
62 | test(); | |
63 | ||
64 | function getTestCases() { | |
65 | var array = new Array(); | |
66 | ||
67 | for ( j = 0, i = 0x0020; i < 0x007e; i++, j++ ) { | |
68 | array[j] = new TestCase( SECTION, "TEST_STRING.charCodeAt("+j+")", i, TEST_STRING.charCodeAt( j ) ); | |
69 | } | |
70 | ||
71 | item = array.length; | |
72 | ||
73 | array[item++] = new TestCase( SECTION, 'TEST_STRING.charCodeAt('+i+')', NaN, TEST_STRING.charCodeAt( i ) ); | |
74 | return array; | |
75 | } | |
76 | ||
77 | function test() { | |
78 | for ( tc = 0; tc < testcases.length; tc++ ) { | |
79 | testcases[tc].passed = writeTestCaseResult( | |
80 | testcases[tc].expect, | |
81 | testcases[tc].actual, | |
82 | testcases[tc].description +" = "+ testcases[tc].actual ); | |
83 | ||
84 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value " | |
85 | } | |
86 | stopTest(); | |
87 | ||
88 | return ( testcases ); | |
89 | } |