Debian Codegraph @

rhino/testsrc/tests/ecma/Types/8.4.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 = '8.4.js';
7
8 /**
9 File Name: 8.4.js
10 ECMA Section: The String type
11 Description:
12
13 The String type is the set of all finite ordered sequences of zero or more
14 Unicode characters. Each character is regarded as occupying a position
15 within the sequence. These positions are identified by nonnegative
16 integers. The leftmost character (if any) is at position 0, the next
17 character (if any) at position 1, and so on. The length of a string is the
18 number of distinct positions within it. The empty string has length zero
19 and therefore contains no characters.
20
21 Author: [email protected]
22 Date: 12 november 1997
23 */
24
25 var SECTION = "8.4";
26 var VERSION = "ECMA_1";
27 startTest();
28 var TITLE = "The String type";
29
30 writeHeaderToLog( SECTION + " "+ TITLE);
31
32 new TestCase( SECTION,
33 "var s = ''; s.length",
34 0,
35 eval("var s = ''; s.length") );
36
37 new TestCase( SECTION,
38 "var s = ''; s.charAt(0)",
39 "",
40 eval("var s = ''; s.charAt(0)") );
41
42
43 for ( var i = 0x0041, TEST_STRING = "", EXPECT_STRING = ""; i < 0x007B; i++ ) {
44 TEST_STRING += ("\\u"+ DecimalToHexString( i ) );
45 EXPECT_STRING += String.fromCharCode(i);
46 }
47
48 new TestCase( SECTION,
49 "var s = '" + TEST_STRING+ "'; s",
50 EXPECT_STRING,
51 eval("var s = '" + TEST_STRING+ "'; s") );
52
53 new TestCase( SECTION,
54 "var s = '" + TEST_STRING+ "'; s.length",
55 0x007B-0x0041,
56 eval("var s = '" + TEST_STRING+ "'; s.length") );
57
58 test();
59
60 function DecimalToHexString( n ) {
61 n = Number( n );
62 var h = "";
63
64 for ( var i = 3; i >= 0; i-- ) {
65 if ( n >= Math.pow(16, i) ){
66 var t = Math.floor( n / Math.pow(16, i));
67 n -= t * Math.pow(16, i);
68 if ( t >= 10 ) {
69 if ( t == 10 ) {
70 h += "A";
71 }
72 if ( t == 11 ) {
73 h += "B";
74 }
75 if ( t == 12 ) {
76 h += "C";
77 }
78 if ( t == 13 ) {
79 h += "D";
80 }
81 if ( t == 14 ) {
82 h += "E";
83 }
84 if ( t == 15 ) {
85 h += "F";
86 }
87 } else {
88 h += String( t );
89 }
90 } else {
91 h += "0";
92 }
93 }
94
95 return h;
96 }
97