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