]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/String/15.5.4.11-2.js
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 ), new Unicode( i
, 6.1));
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 TestCaseMultiExpected( 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 TestCaseMultiExpected( n
, d
, e
, a
) {
111 this.description
= d
;
116 this.bugnumber
= BUGNUMBER
;
118 this.passed
= getTestCaseResultMultiExpected( 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 writeTestCaseResultMultiExpected( expect
, actual
, string
) {
126 var passed
= getTestCaseResultMultiExpected( expect
, actual
);
127 writeFormattedResult( expect
[1].lower
, actual
, string
, passed
);
131 * Added so that either Unicode 4.0, 5.0 or 6.1 results will be considered correct.
132 * Compare expected result to the actual result and figure out whether
133 * the test case passed.
135 function getTestCaseResultMultiExpected( expect
, actual
) {
136 expectedU4
= expect
[0].lower
;
137 expectedU5
= expect
[1].lower
;
138 expectedU6_1
= expect
[2].lower
;
139 // because ( NaN == NaN ) always returns false, need to do
140 // a special compare to see if we got the right result.
141 if ( actual
!= actual
) {
142 if ( typeof actual
== "object" ) {
143 actual
= "NaN object";
145 actual
= "NaN number";
149 if ( expectedU4
!= expectedU4
) {
150 if ( typeof expectedU4
== "object" ) {
151 expectedU4
= "NaN object";
153 expectedU4
= "NaN number";
156 if ( expectedU5
!= expectedU5
) {
157 if ( typeof expectedU5
== "object" ) {
158 expectedU5
= "NaN object";
160 expectedU5
= "NaN number";
163 if ( expectedU6_1
!= expectedU6_1
) {
164 if ( typeof expectedU6_1
== "object" ) {
165 expectedU6_1
= "NaN object";
167 expectedU6_1
= "NaN number";
171 var passed
= ( expectedU4
== actual
|| expectedU5
== actual
|| expectedU6_1
== actual
) ? true : false;
173 // if both objects are numbers
174 // need to replace w/ IEEE standard for rounding
176 typeof(actual
) == "number" &&
177 (typeof(expectedU4
) == "number" ||
178 typeof(expectedU5
) == "number" ||
179 typeof(expectedU6_1
) == "number")) {
180 if (( Math
.abs(actual
-expectedU4
) < 0.0000001 ) || ( Math
.abs(actual
-expectedU5
) < 0.0000001 ) || ( Math
.abs(actual
-expectedU6_1
) < 0.0000001 )) {
185 // verify type is the same
186 if ( typeof(expectedU4
) != typeof(actual
) && typeof(expectedU5
) != typeof(actual
) && typeof(expectedU6_1
) != typeof(actual
) ) {
194 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
195 testcases
[tc
].passed
= writeTestCaseResultMultiExpected(
196 testcases
[tc
].expect
,
197 testcases
[tc
].actual
,
198 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
200 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
203 return ( testcases
);
206 function MyObject( value
) {
208 this.substring
= String
.prototype.substring
;
209 this.toString
= new Function ( "return this.value+''" );
212 function Unicode( c
, version
) {
213 u
= GetUnicodeValues( c
, version
);
219 function GetUnicodeValues( c
, version
) {
225 // upper case Basic Latin
227 if ( c
>= 0x0041 && c
<= 0x005A) {
233 // lower case Basic Latin
234 if ( c
>= 0x0061 && c
<= 0x007a ) {
240 // upper case Latin-1 Supplement
246 if ( (c
>= 0x00C0 && c
<= 0x00D6) || (c
>= 0x00D8 && c
<=0x00DE) ) {
252 // lower case Latin-1 Supplement
253 if ( (c
>= 0x00E0 && c
<= 0x00F6) || (c
>= 0x00F8 && c
<= 0x00FE) ) {
264 if ( (c
>= 0x0100 && c
< 0x0138) || (c
> 0x0149 && c
< 0x0178) ) {
265 // special case for capital I
278 // if it's even, it's a capital and the lower case is c +1
282 // if it's odd, it's a lower case and upper case is c-1
294 if ( (c
>= 0x0139 && c
< 0x0149) || (c
> 0x0178 && c
< 0x017F) ) {
296 // if it's odd, it's a capital and the lower case is c +1
300 // if it's even, it's a lower case and upper case is c-1
312 // need to improve this set
314 if ( c
>= 0x0200 && c
<= 0x0217 ) {
325 // Latin Extended Additional
326 // Range: U+1E00 to U+1EFF
327 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
329 // Spacing Modifier Leters
330 // Range: U+02B0 to U+02FF
332 // Combining Diacritical Marks
333 // Range: U+0300 to U+036F
335 // skip Greek for now
337 // Range: U+0370 to U+03FF
340 // Range: U+0400 to U+04FF
342 if ( c
>= 0x0400 && c
<= 0x040F) {
349 if ( c
>= 0x0410 && c
<= 0x042F ) {
355 if ( c
>= 0x0430 && c
<= 0x044F ) {
361 if ( c
>= 0x0450 && c
<= 0x045F ) {
367 if ( c
>= 0x0460 && c
<= 0x047F ) {
379 // Range: U+0530 to U+058F
380 if ( c
>= 0x0531 && c
<= 0x0556 ) {
385 if ( c
>= 0x0561 && c
< 0x0587 ) {
392 // Range: U+0590 to U+05FF
396 // Range: U+0600 to U+06FF
399 // Range: U+0900 to U+097F
403 // Range: U+0980 to U+09FF
407 // Range: U+0A00 to U+0A7F
411 // Range: U+0A80 to U+0AFF
415 // Range: U+0B00 to U+0B7F
416 // no capital / lower case
420 // Range: U+0B80 to U+0BFF
421 // no capital / lower case
425 // Range: U+0C00 to U+0C7F
426 // no capital / lower case
430 // Range: U+0C80 to U+0CFF
431 // no capital / lower case
435 // Range: U+0D00 to U+0D7F
438 // Range: U+0E00 to U+0E7F
442 // Range: U+0E80 to U+0EFF
446 // Range: U+0F00 to U+0FBF
449 // Range: U+10A0 to U+10F0
450 if ( version
>= 5 ) {
451 if ( version
>= 6.1 && ( c
== 0x10c7 || c
== 0x10cd ) ) {
453 u
[1] = c
+ 7264; //48;
456 if ( c
>= 0x10A0 && c
<= 0x10C5 ) {
458 u
[1] = c
+ 7264; //48;
461 if ( c
>= 0x2D00 && c
<= 0x2D25 ) {
469 // Range: U+1100 to U+11FF
472 // Range: U+1F00 to U+1FFF
476 // General Punctuation
477 // Range: U+2000 to U+206F
479 // Superscripts and Subscripts
480 // Range: U+2070 to U+209F
483 // Range: U+20A0 to U+20CF
486 // Combining Diacritical Marks for Symbols
487 // Range: U+20D0 to U+20FF
492 // Range: U+2150 to U+218F
497 // Range: U+2190 to U+21FF
499 // Mathematical Operators
500 // Range: U+2200 to U+22FF
502 // Miscellaneous Technical
503 // Range: U+2300 to U+23FF
506 // Range: U+2400 to U+243F
508 // Optical Character Recognition
509 // Range: U+2440 to U+245F
511 // Enclosed Alphanumerics
512 // Range: U+2460 to U+24FF
515 // Range: U+2500 to U+257F
518 // Range: U+2580 to U+259F
521 // Range: U+25A0 to U+25FF
523 // Miscellaneous Symbols
524 // Range: U+2600 to U+26FF
527 // Range: U+2700 to U+27BF
529 // CJK Symbols and Punctuation
530 // Range: U+3000 to U+303F
533 // Range: U+3040 to U+309F
536 // Range: U+30A0 to U+30FF
539 // Range: U+3100 to U+312F
541 // Hangul Compatibility Jamo
542 // Range: U+3130 to U+318F
545 // Range: U+3190 to U+319F
548 // Enclosed CJK Letters and Months
549 // Range: U+3200 to U+32FF
552 // Range: U+3300 to U+33FF
555 // Range: U+AC00 to U+D7A3
558 // Range: U+D800 to U+DB7F
560 // Private Use High Surrogates
561 // Range: U+DB80 to U+DBFF
564 // Range: U+DC00 to U+DFFF
567 // Range: U+E000 to U+F8FF
569 // CJK Compatibility Ideographs
570 // Range: U+F900 to U+FAFF
572 // Alphabetic Presentation Forms
573 // Range: U+FB00 to U+FB4F
575 // Arabic Presentation Forms-A
576 // Range: U+FB50 to U+FDFF
578 // Combining Half Marks
579 // Range: U+FE20 to U+FE2F
581 // CJK Compatibility Forms
582 // Range: U+FE30 to U+FE4F
584 // Small Form Variants
585 // Range: U+FE50 to U+FE6F
587 // Arabic Presentation Forms-B
588 // Range: U+FE70 to U+FEFF
590 // Halfwidth and Fullwidth Forms
591 // Range: U+FF00 to U+FFEF
593 if ( c
>= 0xFF21 && c
<= 0xFF3A ) {
599 if ( c
>= 0xFF41 && c
<= 0xFF5A ) {
606 // Range: U+FFF0 to U+FFFF
611 function DecimalToHexString( n
) {
615 for ( var i
= 3; i
>= 0; i
-- ) {
616 if ( n
>= Math
.pow(16, i
) ){
617 var t
= Math
.floor( n
/ Math
.pow(16, i
));
618 n
-= t
* Math
.pow(16, i
);