Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / String / 15.5.4.11-5.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
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
40 /**
41    File Name:          15.5.4.11-5.js
42    ECMA Section:       15.5.4.11 String.prototype.toLowerCase()
43    Description:
44
45    Returns a string equal in length to the length of the result of converting
46    this object to a string. The result is a string value, not a String object.
47
48    Every character of the result is equal to the corresponding character of the
49    string, unless that character has a Unicode 2.0 uppercase equivalent, in which
50    case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
51    mapping shall be used, which does not depend on implementation or locale.)
52
53    Note that the toLowerCase function is intentionally generic; it does not require
54    that its this value be a String object. Therefore it can be transferred to other
55    kinds of objects for use as a method.
56
57    Author:             christine@netscape.com
58    Date:               12 november 1997
59 */
60
61 var SECTION = "15.5.4.11-5";
62 var VERSION = "ECMA_1";
63 startTest();
64 var TITLE   = "String.prototype.toLowerCase()";
65
66 writeHeaderToLog( SECTION + " "+ TITLE);
67
68 new TestCase( SECTION,  "String.prototype.toLowerCase.length",        0,          String.prototype.toLowerCase.length );
69
70 new TestCase( SECTION,  "delete String.prototype.toLowerCase.length", false,      delete String.prototype.toLowerCase.length );
71
72 new TestCase( SECTION,  "delete String.prototype.toLowerCase.length; String.prototype.toLowerCase.length", 0,      eval("delete String.prototype.toLowerCase.length; String.prototype.toLowerCase.length") );
73
74 // Cyrillic (part)
75 // Range: U+0400 to U+04FF
76 for ( var i = 0x0400; i <= 0x047F; i++ ) {
77   var U = new Unicode( i );
78 /*
79   new TestCase(   SECTION,
80   "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()",
81   String.fromCharCode(U.lower),
82   eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") );
83 */
84   new TestCase(   SECTION,
85                   "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)",
86                   U.lower,
87                   eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
88 }
89
90 test();
91
92 function MyObject( value ) {
93   this.value = value;
94   this.substring = String.prototype.substring;
95   this.toString = new Function ( "return this.value+''" );
96 }
97 function Unicode( c ) {
98   u = GetUnicodeValues( c );
99   this.upper = u[0];
100   this.lower = u[1]
101     return this;
102 }
103 function GetUnicodeValues( c ) {
104   u = new Array();
105
106   u[0] = c;
107   u[1] = c;
108
109   // upper case Basic Latin
110
111   if ( c >= 0x0041 && c <= 0x005A) {
112     u[0] = c;
113     u[1] = c + 32;
114     return u;
115   }
116
117   // lower case Basic Latin
118   if ( c >= 0x0061 && c <= 0x007a ) {
119     u[0] = c - 32;
120     u[1] = c;
121     return u;
122   }
123
124   // upper case Latin-1 Supplement
125   if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
126     u[0] = c;
127     u[1] = c + 32;
128     return u;
129   }
130
131   // lower case Latin-1 Supplement
132   if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
133     u[0] = c - 32;
134     u[1] = c;
135     return u;
136   }
137   if ( c == 0x00FF ) {
138     u[0] = 0x0178;
139     u[1] = c;
140     return u;
141   }
142   // Latin Extended A
143   if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
144     // special case for capital I
145     if ( c == 0x0130 ) {
146       u[0] = c;
147       u[1] = 0x0069;
148       return u;
149     }
150     if ( c == 0x0131 ) {
151       u[0] = 0x0049;
152       u[1] = c;
153       return u;
154     }
155
156     if ( c % 2 == 0 ) {
157       // if it's even, it's a capital and the lower case is c +1
158       u[0] = c;
159       u[1] = c+1;
160     } else {
161       // if it's odd, it's a lower case and upper case is c-1
162       u[0] = c-1;
163       u[1] = c;
164     }
165     return u;
166   }
167   if ( c == 0x0178 ) {
168     u[0] = c;
169     u[1] = 0x00FF;
170     return u;
171   }
172
173   if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
174     if ( c % 2 == 1 ) {
175       // if it's odd, it's a capital and the lower case is c +1
176       u[0] = c;
177       u[1] = c+1;
178     } else {
179       // if it's even, it's a lower case and upper case is c-1
180       u[0] = c-1;
181       u[1] = c;
182     }
183     return u;
184   }
185   if ( c == 0x017F ) {
186     u[0] = 0x0053;
187     u[1] = c;
188   }
189
190   // Latin Extended B
191   // need to improve this set
192
193   if ( c >= 0x0200 && c <= 0x0217 ) {
194     if ( c % 2 == 0 ) {
195       u[0] = c;
196       u[1] = c+1;
197     } else {
198       u[0] = c-1;
199       u[1] = c;
200     }
201     return u;
202   }
203
204   // Latin Extended Additional
205   // Range: U+1E00 to U+1EFF
206   // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
207
208   // Spacing Modifier Leters
209   // Range: U+02B0 to U+02FF
210
211   // Combining Diacritical Marks
212   // Range: U+0300 to U+036F
213
214   // skip Greek for now
215   // Greek
216   // Range: U+0370 to U+03FF
217
218   // Cyrillic
219   // Range: U+0400 to U+04FF
220
221   if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
222     u[0] = c;
223     u[1] = c + 80;
224     return u;
225   }
226
227
228   if ( c >= 0x0410  && c <= 0x042F ) {
229     u[0] = c;
230     u[1] = c + 32;
231     return u;
232   }
233
234   if ( c >= 0x0430 && c<= 0x044F ) {
235     u[0] = c - 32;
236     u[1] = c;
237     return u;
238
239   }
240   if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
241     u[0] = c -80;
242     u[1] = c;
243     return u;
244   }
245
246   if ( c >= 0x0460 && c <= 0x047F ) {
247     if ( c % 2 == 0 ) {
248       u[0] = c;
249       u[1] = c +1;
250     } else {
251       u[0] = c - 1;
252       u[1] = c;
253     }
254     return u;
255   }
256
257   // Armenian
258   // Range: U+0530 to U+058F
259   if ( c >= 0x0531 && c <= 0x0556 ) {
260     u[0] = c;
261     u[1] = c + 48;
262     return u;
263   }
264   if ( c >= 0x0561 && c < 0x0587 ) {
265     u[0] = c - 48;
266     u[1] = c;
267     return u;
268   }
269
270   // Hebrew
271   // Range: U+0590 to U+05FF
272
273
274   // Arabic
275   // Range: U+0600 to U+06FF
276
277   // Devanagari
278   // Range: U+0900 to U+097F
279
280
281   // Bengali
282   // Range: U+0980 to U+09FF
283
284
285   // Gurmukhi
286   // Range: U+0A00 to U+0A7F
287
288
289   // Gujarati
290   // Range: U+0A80 to U+0AFF
291
292
293   // Oriya
294   // Range: U+0B00 to U+0B7F
295   // no capital / lower case
296
297
298   // Tamil
299   // Range: U+0B80 to U+0BFF
300   // no capital / lower case
301
302
303   // Telugu
304   // Range: U+0C00 to U+0C7F
305   // no capital / lower case
306
307
308   // Kannada
309   // Range: U+0C80 to U+0CFF
310   // no capital / lower case
311
312
313   // Malayalam
314   // Range: U+0D00 to U+0D7F
315
316   // Thai
317   // Range: U+0E00 to U+0E7F
318
319
320   // Lao
321   // Range: U+0E80 to U+0EFF
322
323
324   // Tibetan
325   // Range: U+0F00 to U+0FBF
326
327   // Georgian
328   // Range: U+10A0 to U+10F0
329   if ( c >= 0x10A0 && c <= 0x10C5 ) {
330     u[0] = c;
331     u[1] = c + 48;
332     return u;
333   }
334   if ( c >= 0x10D0 && c <= 0x10F5 ) {
335     u[0] = c;
336     u[1] = c;
337     return u;
338   }
339
340   // Hangul Jamo
341   // Range: U+1100 to U+11FF
342
343   // Greek Extended
344   // Range: U+1F00 to U+1FFF
345   // skip for now
346
347
348   // General Punctuation
349   // Range: U+2000 to U+206F
350
351   // Superscripts and Subscripts
352   // Range: U+2070 to U+209F
353
354   // Currency Symbols
355   // Range: U+20A0 to U+20CF
356
357
358   // Combining Diacritical Marks for Symbols
359   // Range: U+20D0 to U+20FF
360   // skip for now
361
362
363   // Number Forms
364   // Range: U+2150 to U+218F
365   // skip for now
366
367
368   // Arrows
369   // Range: U+2190 to U+21FF
370
371   // Mathematical Operators
372   // Range: U+2200 to U+22FF
373
374   // Miscellaneous Technical
375   // Range: U+2300 to U+23FF
376
377   // Control Pictures
378   // Range: U+2400 to U+243F
379
380   // Optical Character Recognition
381   // Range: U+2440 to U+245F
382
383   // Enclosed Alphanumerics
384   // Range: U+2460 to U+24FF
385
386   // Box Drawing
387   // Range: U+2500 to U+257F
388
389   // Block Elements
390   // Range: U+2580 to U+259F
391
392   // Geometric Shapes
393   // Range: U+25A0 to U+25FF
394
395   // Miscellaneous Symbols
396   // Range: U+2600 to U+26FF
397
398   // Dingbats
399   // Range: U+2700 to U+27BF
400
401   // CJK Symbols and Punctuation
402   // Range: U+3000 to U+303F
403
404   // Hiragana
405   // Range: U+3040 to U+309F
406
407   // Katakana
408   // Range: U+30A0 to U+30FF
409
410   // Bopomofo
411   // Range: U+3100 to U+312F
412
413   // Hangul Compatibility Jamo
414   // Range: U+3130 to U+318F
415
416   // Kanbun
417   // Range: U+3190 to U+319F
418
419
420   // Enclosed CJK Letters and Months
421   // Range: U+3200 to U+32FF
422
423   // CJK Compatibility
424   // Range: U+3300 to U+33FF
425
426   // Hangul Syllables
427   // Range: U+AC00 to U+D7A3
428
429   // High Surrogates
430   // Range: U+D800 to U+DB7F
431
432   // Private Use High Surrogates
433   // Range: U+DB80 to U+DBFF
434
435   // Low Surrogates
436   // Range: U+DC00 to U+DFFF
437
438   // Private Use Area
439   // Range: U+E000 to U+F8FF
440
441   // CJK Compatibility Ideographs
442   // Range: U+F900 to U+FAFF
443
444   // Alphabetic Presentation Forms
445   // Range: U+FB00 to U+FB4F
446
447   // Arabic Presentation Forms-A
448   // Range: U+FB50 to U+FDFF
449
450   // Combining Half Marks
451   // Range: U+FE20 to U+FE2F
452
453   // CJK Compatibility Forms
454   // Range: U+FE30 to U+FE4F
455
456   // Small Form Variants
457   // Range: U+FE50 to U+FE6F
458
459   // Arabic Presentation Forms-B
460   // Range: U+FE70 to U+FEFF
461
462   // Halfwidth and Fullwidth Forms
463   // Range: U+FF00 to U+FFEF
464
465   if ( c >= 0xFF21 && c <= 0xFF3A ) {
466     u[0] = c;
467     u[1] = c + 32;
468     return u;
469   }
470
471   if ( c >= 0xFF41 && c <= 0xFF5A ) {
472     u[0] = c - 32;
473     u[1] = c;
474     return u;
475   }
476
477   // Specials
478   // Range: U+FFF0 to U+FFFF
479
480   return u;
481 }
482
483 function DecimalToHexString( n ) {
484   n = Number( n );
485   var h = "0x";
486
487   for ( var i = 3; i >= 0; i-- ) {
488     if ( n >= Math.pow(16, i) ){
489       var t = Math.floor( n  / Math.pow(16, i));
490       n -= t * Math.pow(16, i);
491       if ( t >= 10 ) {
492         if ( t == 10 ) {
493           h += "A";
494         }
495         if ( t == 11 ) {
496           h += "B";
497         }
498         if ( t == 12 ) {
499           h += "C";
500         }
501         if ( t == 13 ) {
502           h += "D";
503         }
504         if ( t == 14 ) {
505           h += "E";
506         }
507         if ( t == 15 ) {
508           h += "F";
509         }
510       } else {
511         h += String( t );
512       }
513     } else {
514       h += "0";
515     }
516   }
517
518   return h;
519 }