js/src/tests/ecma/String/15.5.4.12-3.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial