]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/String/15.5.4.11-6.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.5.4.11-6.js
24 ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
27 Returns a string equal in length to the length of the result of converting
28 this object to a string. The result is a string value, not a String object.
30 Every character of the result is equal to the corresponding character of the
31 string, unless that character has a Unicode 2.0 uppercase equivalent, in which
32 case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
33 mapping shall be used, which does not depend on implementation or locale.)
35 Note that the toLowerCase function is intentionally generic; it does not require
36 that its this value be a String object. Therefore it can be transferred to other
37 kinds of objects for use as a method.
39 Author: christine@netscape.com
40 Date: 12 november 1997
43 var SECTION
= "15.5.4.11-6";
44 var VERSION
= "ECMA_1";
46 var TITLE
= "String.prototype.toLowerCase()";
48 writeHeaderToLog( SECTION
+ " "+ TITLE
);
50 var testcases
= getTestCases();
53 function getTestCases() {
54 var array
= new Array();
58 // Range: U+0530 to U+058F
59 for ( var i
= 0x0530; i
<= 0x058F; i
++ ) {
61 var U
= new Unicode( i
);
63 array[item++] = new TestCase( SECTION,
64 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()",
65 String.fromCharCode(U.lower),
66 eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") );
68 array
[item
++] = new TestCase( SECTION
,
69 "var s = new String( String.fromCharCode("+i
+") ); s.toLowerCase().charCodeAt(0)",
71 eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
77 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
78 testcases
[tc
].passed
= writeTestCaseResult(
81 testcases
[tc
].description
+" = "+
82 testcases
[tc
].actual
);
84 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
89 function MyObject( value
) {
91 this.substring
= String
.prototype.substring
;
92 this.toString
= new Function ( "return this.value+''" );
94 function Unicode( c
) {
95 u
= GetUnicodeValues( c
);
100 function GetUnicodeValues( c
) {
106 // upper case Basic Latin
108 if ( c
>= 0x0041 && c
<= 0x005A) {
114 // lower case Basic Latin
115 if ( c
>= 0x0061 && c
<= 0x007a ) {
121 // upper case Latin-1 Supplement
127 if ( (c
>= 0x00C0 && c
<= 0x00D6) || (c
>= 0x00D8 && c
<=0x00DE) ) {
133 // lower case Latin-1 Supplement
134 if ( (c
>= 0x00E0 && c
<= 0x00F6) || (c
>= 0x00F8 && c
<= 0x00FE) ) {
145 if ( (c
>= 0x0100 && c
< 0x0138) || (c
> 0x0149 && c
< 0x0178) ) {
146 // special case for capital I
159 // if it's even, it's a capital and the lower case is c +1
163 // if it's odd, it's a lower case and upper case is c-1
175 if ( (c
>= 0x0139 && c
< 0x0149) || (c
> 0x0178 && c
< 0x017F) ) {
177 // if it's odd, it's a capital and the lower case is c +1
181 // if it's even, it's a lower case and upper case is c-1
193 // need to improve this set
195 if ( c
>= 0x0200 && c
<= 0x0217 ) {
206 // Latin Extended Additional
207 // Range: U+1E00 to U+1EFF
208 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
210 // Spacing Modifier Leters
211 // Range: U+02B0 to U+02FF
213 // Combining Diacritical Marks
214 // Range: U+0300 to U+036F
216 // skip Greek for now
218 // Range: U+0370 to U+03FF
221 // Range: U+0400 to U+04FF
223 if ( c
>= 0x0400 && c
<= 0x040F) {
230 if ( c
>= 0x0410 && c
<= 0x042F ) {
236 if ( c
>= 0x0430 && c
<= 0x044F ) {
242 if ( c
>= 0x0450 && c
<= 0x045F ) {
248 if ( c
>= 0x0460 && c
<= 0x047F ) {
260 // Range: U+0530 to U+058F
261 if ( c
>= 0x0531 && c
<= 0x0556 ) {
266 if ( c
>= 0x0561 && c
< 0x0587 ) {
273 // Range: U+0590 to U+05FF
277 // Range: U+0600 to U+06FF
280 // Range: U+0900 to U+097F
284 // Range: U+0980 to U+09FF
288 // Range: U+0A00 to U+0A7F
292 // Range: U+0A80 to U+0AFF
296 // Range: U+0B00 to U+0B7F
297 // no capital / lower case
301 // Range: U+0B80 to U+0BFF
302 // no capital / lower case
306 // Range: U+0C00 to U+0C7F
307 // no capital / lower case
311 // Range: U+0C80 to U+0CFF
312 // no capital / lower case
316 // Range: U+0D00 to U+0D7F
319 // Range: U+0E00 to U+0E7F
323 // Range: U+0E80 to U+0EFF
327 // Range: U+0F00 to U+0FBF
330 // Range: U+10A0 to U+10F0
333 // Range: U+1100 to U+11FF
336 // Range: U+1F00 to U+1FFF
340 // General Punctuation
341 // Range: U+2000 to U+206F
343 // Superscripts and Subscripts
344 // Range: U+2070 to U+209F
347 // Range: U+20A0 to U+20CF
350 // Combining Diacritical Marks for Symbols
351 // Range: U+20D0 to U+20FF
356 // Range: U+2150 to U+218F
361 // Range: U+2190 to U+21FF
363 // Mathematical Operators
364 // Range: U+2200 to U+22FF
366 // Miscellaneous Technical
367 // Range: U+2300 to U+23FF
370 // Range: U+2400 to U+243F
372 // Optical Character Recognition
373 // Range: U+2440 to U+245F
375 // Enclosed Alphanumerics
376 // Range: U+2460 to U+24FF
379 // Range: U+2500 to U+257F
382 // Range: U+2580 to U+259F
385 // Range: U+25A0 to U+25FF
387 // Miscellaneous Symbols
388 // Range: U+2600 to U+26FF
391 // Range: U+2700 to U+27BF
393 // CJK Symbols and Punctuation
394 // Range: U+3000 to U+303F
397 // Range: U+3040 to U+309F
400 // Range: U+30A0 to U+30FF
403 // Range: U+3100 to U+312F
405 // Hangul Compatibility Jamo
406 // Range: U+3130 to U+318F
409 // Range: U+3190 to U+319F
412 // Enclosed CJK Letters and Months
413 // Range: U+3200 to U+32FF
416 // Range: U+3300 to U+33FF
419 // Range: U+AC00 to U+D7A3
422 // Range: U+D800 to U+DB7F
424 // Private Use High Surrogates
425 // Range: U+DB80 to U+DBFF
428 // Range: U+DC00 to U+DFFF
431 // Range: U+E000 to U+F8FF
433 // CJK Compatibility Ideographs
434 // Range: U+F900 to U+FAFF
436 // Alphabetic Presentation Forms
437 // Range: U+FB00 to U+FB4F
439 // Arabic Presentation Forms-A
440 // Range: U+FB50 to U+FDFF
442 // Combining Half Marks
443 // Range: U+FE20 to U+FE2F
445 // CJK Compatibility Forms
446 // Range: U+FE30 to U+FE4F
448 // Small Form Variants
449 // Range: U+FE50 to U+FE6F
451 // Arabic Presentation Forms-B
452 // Range: U+FE70 to U+FEFF
454 // Halfwidth and Fullwidth Forms
455 // Range: U+FF00 to U+FFEF
457 if ( c
>= 0xFF21 && c
<= 0xFF3A ) {
463 if ( c
>= 0xFF41 && c
<= 0xFF5A ) {
470 // Range: U+FFF0 to U+FFFF
475 function DecimalToHexString( n
) {
479 for ( var i
= 3; i
>= 0; i
-- ) {
480 if ( n
>= Math
.pow(16, i
) ){
481 var t
= Math
.floor( n
/ Math
.pow(16, i
));
482 n
-= t
* Math
.pow(16, i
);