]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/GlobalObject/15.1.2.5-2.js
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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
23 File Name: 15.1.2.5-2.js
24 ECMA Section: 15.1.2.5 Function properties of the global object
28 This tests the cases where there are fewer than 4 characters following "%u",
29 or fewer than 2 characters following "%" or "%u".
31 The unescape function computes a new version of a string value in which
32 each escape sequences of the sort that might be introduced by the escape
33 function is replaced with the character that it represents.
35 When the unescape function is called with one argument string, the
36 following steps are taken:
38 1. Call ToString(string).
39 2. Compute the number of characters in Result(1).
40 3. Let R be the empty string.
42 5. If k equals Result(2), return R.
43 6. Let c be the character at position k within Result(1).
44 7. If c is not %, go to step 18.
45 8. If k is greater than Result(2)-6, go to step 14.
46 9. If the character at position k+1 within result(1) is not u, go to step
48 10. If the four characters at positions k+2, k+3, k+4, and k+5 within
49 Result(1) are not all hexadecimal digits, go to step 14.
50 11. Let c be the character whose Unicode encoding is the integer represented
51 by the four hexadecimal digits at positions k+2, k+3, k+4, and k+5
55 14. If k is greater than Result(2)-3, go to step 18.
56 15. If the two characters at positions k+1 and k+2 within Result(1) are not
57 both hexadecimal digits, go to step 18.
58 16. Let c be the character whose Unicode encoding is the integer represented
59 by two zeroes plus the two hexadecimal digits at positions k+1 and k+2
62 18. Let R be a new string value computed by concatenating the previous value
66 Author: christine@netscape.com
70 var SECTION
= "15.1.2.5-2";
71 var VERSION
= "ECMA_1";
73 var TITLE
= "unescape(string)";
75 writeHeaderToLog( SECTION
+ " "+ TITLE
);
77 var testcases
= getTestCases();
81 function getTestCases() {
82 var array
= new Array();
85 // since there is only one character following "%", no conversion should occur.
87 for ( var CHARCODE
= 0; CHARCODE
< 256; CHARCODE
+= 16 ) {
88 array
[item
++] = new TestCase( SECTION
,
89 "unescape( %"+ (ToHexString(CHARCODE
)).substring(0,1) +" )",
90 "%"+(ToHexString(CHARCODE
)).substring(0,1),
91 unescape( "%" + (ToHexString(CHARCODE
)).substring(0,1) ) );
94 // since there is only one character following "%u", no conversion should occur.
96 for ( var CHARCODE
= 0; CHARCODE
< 256; CHARCODE
+=16 ) {
97 array
[item
++] = new TestCase( SECTION
,
98 "unescape( %u"+ (ToHexString(CHARCODE
)).substring(0,1) +" )",
99 "%u"+(ToHexString(CHARCODE
)).substring(0,1),
100 unescape( "%u" + (ToHexString(CHARCODE
)).substring(0,1) ) );
104 // three char unicode string. no conversion should occur
106 for ( var CHARCODE
= 1024; CHARCODE
< 65536; CHARCODE
+= 1234 ) {
107 array
[item
++] = new TestCase
109 "unescape( %u"+ (ToUnicodeString(CHARCODE
)).substring(0,3)+ " )",
111 "%u"+(ToUnicodeString(CHARCODE
)).substring(0,3),
112 unescape( "%u"+(ToUnicodeString(CHARCODE
)).substring(0,3) )
119 function ToUnicodeString( n
) {
120 var string
= ToHexString(n
);
122 for ( var PAD
= (4 - string
.length
); PAD
> 0; PAD
-- ) {
123 string
= "0" + string
;
128 function ToHexString( n
) {
129 var hex
= new Array();
131 for ( var mag
= 1; Math
.pow(16,mag
) <= n
; mag
++ ) {
135 for ( index
= 0, mag
-= 1; mag
> 0; index
++, mag
-- ) {
136 hex
[index
] = Math
.floor( n
/ Math
.pow(16,mag
) );
137 n
-= Math
.pow(16,mag
) * Math
.floor( n
/Math
.pow(16,mag
) );
140 hex
[hex
.length
] = n
% 16;
144 for ( var index
= 0 ; index
< hex
.length
; index
++ ) {
145 switch ( hex
[index
] ) {
165 string
+= hex
[index
];
169 if ( string
.length
== 1 ) {
170 string
= "0" + string
;
175 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
176 testcases
[tc
].passed
= writeTestCaseResult(
177 testcases
[tc
].expect
,
178 testcases
[tc
].actual
,
179 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
180 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
183 return ( testcases
);