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