]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma/String/15.5.4.11-2.js
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma / String / 15.5.4.11-2.js
CommitLineData
b37bf2e1
A
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
4 *
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/
9 *
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
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
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.
22 *
23 * Contributor(s):
24 *
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.
36 *
37 * ***** END LICENSE BLOCK ***** */
38/**
39 File Name: 15.5.4.11-2.js
40 ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
41 Description:
42
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.
45
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.)
50
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.
54
55 Author: christine@netscape.com
56 Date: 12 november 1997
57*/
58/*
59 Safari Changes: This test differs from the mozilla tests in two significant
60 ways.
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)
69*/
70 var SECTION = "15.5.4.11-2";
71 var VERSION = "ECMA_1";
72 startTest();
73 var TITLE = "String.prototype.toLowerCase()";
74
75 writeHeaderToLog( SECTION + " "+ TITLE);
76
77 var testcases = getTestCases();
78 test();
79
80function getTestCases() {
81 var array = new Array();
82 var item = 0;
83
84 // Georgian
85 // Range: U+10A0 to U+10FF
86 for ( var i = 0x10A0; i <= 0x10FF; i++ ) {
6fe7ccc8 87 var U = new Array(new Unicode( i, 4 ), new Unicode( i, 5 ), new Unicode( i, 6.1));
b37bf2e1
A
88
89/*
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()") );
94*/
6fe7ccc8 95 array[item++] = new TestCaseMultiExpected( SECTION,
b37bf2e1
A
96 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)",
97 U,
98 eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
99 }
100
101 return array;
102}
103
104/*
105 * TestCase constructor
106 *
107 */
108
6fe7ccc8 109function TestCaseMultiExpected( n, d, e, a ) {
b37bf2e1
A
110 this.name = n;
111 this.description = d;
112 this.expect = e;
113 this.actual = a;
114 this.passed = true;
115 this.reason = "";
116 this.bugnumber = BUGNUMBER;
117
6fe7ccc8 118 this.passed = getTestCaseResultMultiExpected( this.expect, this.actual );
b37bf2e1
A
119 if ( DEBUG ) {
120 writeLineToLog( "added " + this.description );
121 }
122}
123
124// Added so that either Unicode 4.0 or 5.0 results will be considered correct.
6fe7ccc8
A
125function writeTestCaseResultMultiExpected( expect, actual, string ) {
126 var passed = getTestCaseResultMultiExpected( expect, actual );
b37bf2e1
A
127 writeFormattedResult( expect[1].lower, actual, string, passed );
128 return passed;
129}
130/*
6fe7ccc8 131 * Added so that either Unicode 4.0, 5.0 or 6.1 results will be considered correct.
b37bf2e1
A
132 * Compare expected result to the actual result and figure out whether
133 * the test case passed.
134 */
6fe7ccc8 135function getTestCaseResultMultiExpected( expect, actual ) {
b37bf2e1
A
136 expectedU4 = expect[0].lower;
137 expectedU5 = expect[1].lower;
6fe7ccc8 138 expectedU6_1 = expect[2].lower;
b37bf2e1
A
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";
144 } else {
145 actual = "NaN number";
146 }
147 }
148
149 if ( expectedU4 != expectedU4 ) {
150 if ( typeof expectedU4 == "object" ) {
151 expectedU4 = "NaN object";
152 } else {
153 expectedU4 = "NaN number";
154 }
155 }
156 if ( expectedU5 != expectedU5 ) {
157 if ( typeof expectedU5 == "object" ) {
158 expectedU5 = "NaN object";
159 } else {
160 expectedU5 = "NaN number";
161 }
162 }
6fe7ccc8
A
163 if ( expectedU6_1 != expectedU6_1 ) {
164 if ( typeof expectedU6_1 == "object" ) {
165 expectedU6_1 = "NaN object";
166 } else {
167 expectedU6_1 = "NaN number";
168 }
169 }
b37bf2e1 170
6fe7ccc8 171 var passed = ( expectedU4 == actual || expectedU5 == actual || expectedU6_1 == actual ) ? true : false;
b37bf2e1
A
172
173 // if both objects are numbers
174 // need to replace w/ IEEE standard for rounding
175 if ( !passed &&
176 typeof(actual) == "number" &&
177 (typeof(expectedU4) == "number" ||
6fe7ccc8
A
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 )) {
b37bf2e1
A
181 passed = true;
182 }
183 }
184
185 // verify type is the same
6fe7ccc8 186 if ( typeof(expectedU4) != typeof(actual) && typeof(expectedU5) != typeof(actual) && typeof(expectedU6_1) != typeof(actual) ) {
b37bf2e1
A
187 passed = false;
188 }
189
190 return passed;
191}
192
193function test() {
194 for ( tc=0; tc < testcases.length; tc++ ) {
6fe7ccc8 195 testcases[tc].passed = writeTestCaseResultMultiExpected(
b37bf2e1
A
196 testcases[tc].expect,
197 testcases[tc].actual,
198 testcases[tc].description +" = "+ testcases[tc].actual );
199
200 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
201 }
202 stopTest();
203 return ( testcases );
204}
205
206function MyObject( value ) {
207 this.value = value;
208 this.substring = String.prototype.substring;
209 this.toString = new Function ( "return this.value+''" );
210}
211
212function Unicode( c, version ) {
213 u = GetUnicodeValues( c, version );
214 this.upper = u[0];
215 this.lower = u[1]
216 return this;
217}
218
219function GetUnicodeValues( c, version ) {
220 u = new Array();
221
222 u[0] = c;
223 u[1] = c;
224
225 // upper case Basic Latin
226
227 if ( c >= 0x0041 && c <= 0x005A) {
228 u[0] = c;
229 u[1] = c + 32;
230 return u;
231 }
232
233 // lower case Basic Latin
234 if ( c >= 0x0061 && c <= 0x007a ) {
235 u[0] = c - 32;
236 u[1] = c;
237 return u;
238 }
239
240 // upper case Latin-1 Supplement
241 if ( c == 0x00B5 ) {
242 u[0] = c;
243 u[1] = 0x039C;
244 return u;
245 }
246 if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
247 u[0] = c;
248 u[1] = c + 32;
249 return u;
250 }
251
252 // lower case Latin-1 Supplement
253 if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
254 u[0] = c - 32;
255 u[1] = c;
256 return u;
257 }
258 if ( c == 0x00FF ) {
259 u[0] = 0x0178;
260 u[1] = c;
261 return u;
262 }
263 // Latin Extended A
264 if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
265 // special case for capital I
266 if ( c == 0x0130 ) {
267 u[0] = c;
268 u[1] = 0x0069;
269 return u;
270 }
271 if ( c == 0x0131 ) {
272 u[0] = 0x0049;
273 u[1] = c;
274 return u;
275 }
276
277 if ( c % 2 == 0 ) {
278 // if it's even, it's a capital and the lower case is c +1
279 u[0] = c;
280 u[1] = c+1;
281 } else {
282 // if it's odd, it's a lower case and upper case is c-1
283 u[0] = c-1;
284 u[1] = c;
285 }
286 return u;
287 }
288 if ( c == 0x0178 ) {
289 u[0] = c;
290 u[1] = 0x00FF;
291 return u;
292 }
293
294 if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
295 if ( c % 2 == 1 ) {
296 // if it's odd, it's a capital and the lower case is c +1
297 u[0] = c;
298 u[1] = c+1;
299 } else {
300 // if it's even, it's a lower case and upper case is c-1
301 u[0] = c-1;
302 u[1] = c;
303 }
304 return u;
305 }
306 if ( c == 0x017F ) {
307 u[0] = 0x0053;
308 u[1] = c;
309 }
310
311 // Latin Extended B
312 // need to improve this set
313
314 if ( c >= 0x0200 && c <= 0x0217 ) {
315 if ( c % 2 == 0 ) {
316 u[0] = c;
317 u[1] = c+1;
318 } else {
319 u[0] = c-1;
320 u[1] = c;
321 }
322 return u;
323 }
324
325 // Latin Extended Additional
326 // Range: U+1E00 to U+1EFF
327 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
328
329 // Spacing Modifier Leters
330 // Range: U+02B0 to U+02FF
331
332 // Combining Diacritical Marks
333 // Range: U+0300 to U+036F
334
335 // skip Greek for now
336 // Greek
337 // Range: U+0370 to U+03FF
338
339 // Cyrillic
340 // Range: U+0400 to U+04FF
341
342 if ( c >= 0x0400 && c <= 0x040F) {
343 u[0] = c;
344 u[1] = c + 80;
345 return u;
346 }
347
348
349 if ( c >= 0x0410 && c <= 0x042F ) {
350 u[0] = c;
351 u[1] = c + 32;
352 return u;
353 }
354
355 if ( c >= 0x0430 && c<= 0x044F ) {
356 u[0] = c - 32;
357 u[1] = c;
358 return u;
359
360 }
361 if ( c >= 0x0450 && c<= 0x045F ) {
362 u[0] = c -80;
363 u[1] = c;
364 return u;
365 }
366
367 if ( c >= 0x0460 && c <= 0x047F ) {
368 if ( c % 2 == 0 ) {
369 u[0] = c;
370 u[1] = c +1;
371 } else {
372 u[0] = c - 1;
373 u[1] = c;
374 }
375 return u;
376 }
377
378 // Armenian
379 // Range: U+0530 to U+058F
380 if ( c >= 0x0531 && c <= 0x0556 ) {
381 u[0] = c;
382 u[1] = c + 48;
383 return u;
384 }
385 if ( c >= 0x0561 && c < 0x0587 ) {
386 u[0] = c - 48;
387 u[1] = c;
388 return u;
389 }
390
391 // Hebrew
392 // Range: U+0590 to U+05FF
393
394
395 // Arabic
396 // Range: U+0600 to U+06FF
397
398 // Devanagari
399 // Range: U+0900 to U+097F
400
401
402 // Bengali
403 // Range: U+0980 to U+09FF
404
405
406 // Gurmukhi
407 // Range: U+0A00 to U+0A7F
408
409
410 // Gujarati
411 // Range: U+0A80 to U+0AFF
412
413
414 // Oriya
415 // Range: U+0B00 to U+0B7F
416 // no capital / lower case
417
418
419 // Tamil
420 // Range: U+0B80 to U+0BFF
421 // no capital / lower case
422
423
424 // Telugu
425 // Range: U+0C00 to U+0C7F
426 // no capital / lower case
427
428
429 // Kannada
430 // Range: U+0C80 to U+0CFF
431 // no capital / lower case
432
433
434 // Malayalam
435 // Range: U+0D00 to U+0D7F
436
437 // Thai
438 // Range: U+0E00 to U+0E7F
439
440
441 // Lao
442 // Range: U+0E80 to U+0EFF
443
444
445 // Tibetan
446 // Range: U+0F00 to U+0FBF
447
448 // Georgian
449 // Range: U+10A0 to U+10F0
6fe7ccc8
A
450 if ( version >= 5 ) {
451 if ( version >= 6.1 && ( c == 0x10c7 || c == 0x10cd ) ) {
452 u[0] = c;
453 u[1] = c + 7264; //48;
454 return u;
455 }
b37bf2e1
A
456 if ( c >= 0x10A0 && c <= 0x10C5 ) {
457 u[0] = c;
458 u[1] = c + 7264; //48;
459 return u;
460 }
461 if ( c >= 0x2D00 && c <= 0x2D25 ) {
462 u[0] = c;
463 u[1] = c;
464 return u;
465 }
466 }
467
468 // Hangul Jamo
469 // Range: U+1100 to U+11FF
470
471 // Greek Extended
472 // Range: U+1F00 to U+1FFF
473 // skip for now
474
475
476 // General Punctuation
477 // Range: U+2000 to U+206F
478
479 // Superscripts and Subscripts
480 // Range: U+2070 to U+209F
481
482 // Currency Symbols
483 // Range: U+20A0 to U+20CF
484
485
486 // Combining Diacritical Marks for Symbols
487 // Range: U+20D0 to U+20FF
488 // skip for now
489
490
491 // Number Forms
492 // Range: U+2150 to U+218F
493 // skip for now
494
495
496 // Arrows
497 // Range: U+2190 to U+21FF
498
499 // Mathematical Operators
500 // Range: U+2200 to U+22FF
501
502 // Miscellaneous Technical
503 // Range: U+2300 to U+23FF
504
505 // Control Pictures
506 // Range: U+2400 to U+243F
507
508 // Optical Character Recognition
509 // Range: U+2440 to U+245F
510
511 // Enclosed Alphanumerics
512 // Range: U+2460 to U+24FF
513
514 // Box Drawing
515 // Range: U+2500 to U+257F
516
517 // Block Elements
518 // Range: U+2580 to U+259F
519
520 // Geometric Shapes
521 // Range: U+25A0 to U+25FF
522
523 // Miscellaneous Symbols
524 // Range: U+2600 to U+26FF
525
526 // Dingbats
527 // Range: U+2700 to U+27BF
528
529 // CJK Symbols and Punctuation
530 // Range: U+3000 to U+303F
531
532 // Hiragana
533 // Range: U+3040 to U+309F
534
535 // Katakana
536 // Range: U+30A0 to U+30FF
537
538 // Bopomofo
539 // Range: U+3100 to U+312F
540
541 // Hangul Compatibility Jamo
542 // Range: U+3130 to U+318F
543
544 // Kanbun
545 // Range: U+3190 to U+319F
546
547
548 // Enclosed CJK Letters and Months
549 // Range: U+3200 to U+32FF
550
551 // CJK Compatibility
552 // Range: U+3300 to U+33FF
553
554 // Hangul Syllables
555 // Range: U+AC00 to U+D7A3
556
557 // High Surrogates
558 // Range: U+D800 to U+DB7F
559
560 // Private Use High Surrogates
561 // Range: U+DB80 to U+DBFF
562
563 // Low Surrogates
564 // Range: U+DC00 to U+DFFF
565
566 // Private Use Area
567 // Range: U+E000 to U+F8FF
568
569 // CJK Compatibility Ideographs
570 // Range: U+F900 to U+FAFF
571
572 // Alphabetic Presentation Forms
573 // Range: U+FB00 to U+FB4F
574
575 // Arabic Presentation Forms-A
576 // Range: U+FB50 to U+FDFF
577
578 // Combining Half Marks
579 // Range: U+FE20 to U+FE2F
580
581 // CJK Compatibility Forms
582 // Range: U+FE30 to U+FE4F
583
584 // Small Form Variants
585 // Range: U+FE50 to U+FE6F
586
587 // Arabic Presentation Forms-B
588 // Range: U+FE70 to U+FEFF
589
590 // Halfwidth and Fullwidth Forms
591 // Range: U+FF00 to U+FFEF
592
593 if ( c >= 0xFF21 && c <= 0xFF3A ) {
594 u[0] = c;
595 u[1] = c + 32;
596 return u;
597 }
598
599 if ( c >= 0xFF41 && c <= 0xFF5A ) {
600 u[0] = c - 32;
601 u[1] = c;
602 return u;
603 }
604
605 // Specials
606 // Range: U+FFF0 to U+FFFF
607
608 return u;
609}
610
611function DecimalToHexString( n ) {
612 n = Number( n );
613 var h = "0x";
614
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);
619 if ( t >= 10 ) {
620 if ( t == 10 ) {
621 h += "A";
622 }
623 if ( t == 11 ) {
624 h += "B";
625 }
626 if ( t == 12 ) {
627 h += "C";
628 }
629 if ( t == 13 ) {
630 h += "D";
631 }
632 if ( t == 14 ) {
633 h += "E";
634 }
635 if ( t == 15 ) {
636 h += "F";
637 }
638 } else {
639 h += String( t );
640 }
641 } else {
642 h += "0";
643 }
644 }
645
646 return h;
6fe7ccc8 647}