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