]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/String/15.5.4.11-2.js
b75f3e8d65fc0c36cfeb51b520f97e4f040a2f8d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 File Name: 15.5.4.11-2.js
40 ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
43 Returns a string equal in length to the length of the result of converting
44 this object to a string. The result is a string value, not a String object.
46 Every character of the result is equal to the corresponding character of the
47 string, unless that character has a Unicode 2.0 uppercase equivalent, in which
48 case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
49 mapping shall be used, which does not depend on implementation or locale.)
51 Note that the toLowerCase function is intentionally generic; it does not require
52 that its this value be a String object. Therefore it can be transferred to other
53 kinds of objects for use as a method.
55 Author: christine@netscape.com
56 Date: 12 november 1997
59 Safari Changes: This test differs from the mozilla tests in two significant
61 First, the lower case range for Georgian letters in this file is the
62 correct range according to the Unicode 5.0 standard, as opposed to the
63 Georgian caseless range that mozilla uses.
64 Secondly this test uses an array for expected results with two entries,
65 instead of a single expected result. This allows us to accept Unicode 4.0 or
66 Unicode 5.0 results as correct, as opposed to the mozilla test, which assumes
67 Unicode 5.0. This allows Safari to pass this test on OS' with different
68 Unicode standards implemented (e.g. Tiger and XP)
70 var SECTION
= "15.5.4.11-2";
71 var VERSION
= "ECMA_1";
73 var TITLE
= "String.prototype.toLowerCase()";
75 writeHeaderToLog( SECTION
+ " "+ TITLE
);
77 var testcases
= getTestCases();
80 function getTestCases() {
81 var array
= new Array();
85 // Range: U+10A0 to U+10FF
86 for ( var i
= 0x10A0; i
<= 0x10FF; i
++ ) {
87 var U
= new Array(new Unicode( i
, 4 ), new Unicode( i
, 5 ));
90 array[item++] = new TestCase( SECTION,
91 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()",
92 String.fromCharCode(U.lower),
93 eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") );
95 array
[item
++] = new TestCaseDualExpected( SECTION
,
96 "var s = new String( String.fromCharCode("+i
+") ); s.toLowerCase().charCodeAt(0)",
98 eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
105 * TestCase constructor
109 function TestCaseDualExpected( n
, d
, e
, a
) {
111 this.description
= d
;
116 this.bugnumber
= BUGNUMBER
;
118 this.passed
= getTestCaseResultDualExpected( this.expect
, this.actual
);
120 writeLineToLog( "added " + this.description
);
124 // Added so that either Unicode 4.0 or 5.0 results will be considered correct.
125 function writeTestCaseResultDualExpected( expect
, actual
, string
) {
126 var passed
= getTestCaseResultDualExpected( expect
, actual
);
127 writeFormattedResult( expect
[1].lower
, actual
, string
, passed
);
131 * Added so that either Unicode 4.0 or 5.0 results will be considered correct.
132 * Compare expected result to the actual result and figure out whether
133 * the test case passed.
135 function getTestCaseResultDualExpected( expect
, actual
) {
136 expectedU4
= expect
[0].lower
;
137 expectedU5
= expect
[1].lower
;
138 // because ( NaN == NaN ) always returns false, need to do
139 // a special compare to see if we got the right result.
140 if ( actual
!= actual
) {
141 if ( typeof actual
== "object" ) {
142 actual
= "NaN object";
144 actual
= "NaN number";
148 if ( expectedU4
!= expectedU4
) {
149 if ( typeof expectedU4
== "object" ) {
150 expectedU4
= "NaN object";
152 expectedU4
= "NaN number";
155 if ( expectedU5
!= expectedU5
) {
156 if ( typeof expectedU5
== "object" ) {
157 expectedU5
= "NaN object";
159 expectedU5
= "NaN number";
163 var passed
= ( expectedU4
== actual
|| expectedU5
== actual
) ? true : false;
165 // if both objects are numbers
166 // need to replace w/ IEEE standard for rounding
168 typeof(actual
) == "number" &&
169 (typeof(expectedU4
) == "number" ||
170 typeof(expectedU5
) == "number")) {
171 if (( Math
.abs(actual
-expectedU4
) < 0.0000001 ) || ( Math
.abs(actual
-expectedU5
) < 0.0000001 )) {
176 // verify type is the same
177 if ( typeof(expectedU4
) != typeof(actual
) && typeof(expectedU5
) != typeof(actual
) ) {
185 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
186 testcases
[tc
].passed
= writeTestCaseResultDualExpected(
187 testcases
[tc
].expect
,
188 testcases
[tc
].actual
,
189 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
191 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
194 return ( testcases
);
197 function MyObject( value
) {
199 this.substring
= String
.prototype.substring
;
200 this.toString
= new Function ( "return this.value+''" );
203 function Unicode( c
, version
) {
204 u
= GetUnicodeValues( c
, version
);
210 function GetUnicodeValues( c
, version
) {
216 // upper case Basic Latin
218 if ( c
>= 0x0041 && c
<= 0x005A) {
224 // lower case Basic Latin
225 if ( c
>= 0x0061 && c
<= 0x007a ) {
231 // upper case Latin-1 Supplement
237 if ( (c
>= 0x00C0 && c
<= 0x00D6) || (c
>= 0x00D8 && c
<=0x00DE) ) {
243 // lower case Latin-1 Supplement
244 if ( (c
>= 0x00E0 && c
<= 0x00F6) || (c
>= 0x00F8 && c
<= 0x00FE) ) {
255 if ( (c
>= 0x0100 && c
< 0x0138) || (c
> 0x0149 && c
< 0x0178) ) {
256 // special case for capital I
269 // if it's even, it's a capital and the lower case is c +1
273 // if it's odd, it's a lower case and upper case is c-1
285 if ( (c
>= 0x0139 && c
< 0x0149) || (c
> 0x0178 && c
< 0x017F) ) {
287 // if it's odd, it's a capital and the lower case is c +1
291 // if it's even, it's a lower case and upper case is c-1
303 // need to improve this set
305 if ( c
>= 0x0200 && c
<= 0x0217 ) {
316 // Latin Extended Additional
317 // Range: U+1E00 to U+1EFF
318 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
320 // Spacing Modifier Leters
321 // Range: U+02B0 to U+02FF
323 // Combining Diacritical Marks
324 // Range: U+0300 to U+036F
326 // skip Greek for now
328 // Range: U+0370 to U+03FF
331 // Range: U+0400 to U+04FF
333 if ( c
>= 0x0400 && c
<= 0x040F) {
340 if ( c
>= 0x0410 && c
<= 0x042F ) {
346 if ( c
>= 0x0430 && c
<= 0x044F ) {
352 if ( c
>= 0x0450 && c
<= 0x045F ) {
358 if ( c
>= 0x0460 && c
<= 0x047F ) {
370 // Range: U+0530 to U+058F
371 if ( c
>= 0x0531 && c
<= 0x0556 ) {
376 if ( c
>= 0x0561 && c
< 0x0587 ) {
383 // Range: U+0590 to U+05FF
387 // Range: U+0600 to U+06FF
390 // Range: U+0900 to U+097F
394 // Range: U+0980 to U+09FF
398 // Range: U+0A00 to U+0A7F
402 // Range: U+0A80 to U+0AFF
406 // Range: U+0B00 to U+0B7F
407 // no capital / lower case
411 // Range: U+0B80 to U+0BFF
412 // no capital / lower case
416 // Range: U+0C00 to U+0C7F
417 // no capital / lower case
421 // Range: U+0C80 to U+0CFF
422 // no capital / lower case
426 // Range: U+0D00 to U+0D7F
429 // Range: U+0E00 to U+0E7F
433 // Range: U+0E80 to U+0EFF
437 // Range: U+0F00 to U+0FBF
440 // Range: U+10A0 to U+10F0
441 if ( version
== 5 ) {
442 if ( c
>= 0x10A0 && c
<= 0x10C5 ) {
444 u
[1] = c
+ 7264; //48;
447 if ( c
>= 0x2D00 && c
<= 0x2D25 ) {
455 // Range: U+1100 to U+11FF
458 // Range: U+1F00 to U+1FFF
462 // General Punctuation
463 // Range: U+2000 to U+206F
465 // Superscripts and Subscripts
466 // Range: U+2070 to U+209F
469 // Range: U+20A0 to U+20CF
472 // Combining Diacritical Marks for Symbols
473 // Range: U+20D0 to U+20FF
478 // Range: U+2150 to U+218F
483 // Range: U+2190 to U+21FF
485 // Mathematical Operators
486 // Range: U+2200 to U+22FF
488 // Miscellaneous Technical
489 // Range: U+2300 to U+23FF
492 // Range: U+2400 to U+243F
494 // Optical Character Recognition
495 // Range: U+2440 to U+245F
497 // Enclosed Alphanumerics
498 // Range: U+2460 to U+24FF
501 // Range: U+2500 to U+257F
504 // Range: U+2580 to U+259F
507 // Range: U+25A0 to U+25FF
509 // Miscellaneous Symbols
510 // Range: U+2600 to U+26FF
513 // Range: U+2700 to U+27BF
515 // CJK Symbols and Punctuation
516 // Range: U+3000 to U+303F
519 // Range: U+3040 to U+309F
522 // Range: U+30A0 to U+30FF
525 // Range: U+3100 to U+312F
527 // Hangul Compatibility Jamo
528 // Range: U+3130 to U+318F
531 // Range: U+3190 to U+319F
534 // Enclosed CJK Letters and Months
535 // Range: U+3200 to U+32FF
538 // Range: U+3300 to U+33FF
541 // Range: U+AC00 to U+D7A3
544 // Range: U+D800 to U+DB7F
546 // Private Use High Surrogates
547 // Range: U+DB80 to U+DBFF
550 // Range: U+DC00 to U+DFFF
553 // Range: U+E000 to U+F8FF
555 // CJK Compatibility Ideographs
556 // Range: U+F900 to U+FAFF
558 // Alphabetic Presentation Forms
559 // Range: U+FB00 to U+FB4F
561 // Arabic Presentation Forms-A
562 // Range: U+FB50 to U+FDFF
564 // Combining Half Marks
565 // Range: U+FE20 to U+FE2F
567 // CJK Compatibility Forms
568 // Range: U+FE30 to U+FE4F
570 // Small Form Variants
571 // Range: U+FE50 to U+FE6F
573 // Arabic Presentation Forms-B
574 // Range: U+FE70 to U+FEFF
576 // Halfwidth and Fullwidth Forms
577 // Range: U+FF00 to U+FFEF
579 if ( c
>= 0xFF21 && c
<= 0xFF3A ) {
585 if ( c
>= 0xFF41 && c
<= 0xFF5A ) {
592 // Range: U+FFF0 to U+FFFF
597 function DecimalToHexString( n
) {
601 for ( var i
= 3; i
>= 0; i
-- ) {
602 if ( n
>= Math
.pow(16, i
) ){
603 var t
= Math
.floor( n
/ Math
.pow(16, i
));
604 n
-= t
* Math
.pow(16, i
);