1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/String/15.5.4.11-4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,473 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 15.5.4.11-2.js 1.12 + ECMA Section: 15.5.4.11 String.prototype.toLowerCase() 1.13 + Description: 1.14 + 1.15 + Returns a string equal in length to the length of the result of converting 1.16 + this object to a string. The result is a string value, not a String object. 1.17 + 1.18 + Every character of the result is equal to the corresponding character of the 1.19 + string, unless that character has a Unicode 2.0 uppercase equivalent, in which 1.20 + case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case 1.21 + mapping shall be used, which does not depend on implementation or locale.) 1.22 + 1.23 + Note that the toLowerCase function is intentionally generic; it does not require 1.24 + that its this value be a String object. Therefore it can be transferred to other 1.25 + kinds of objects for use as a method. 1.26 + 1.27 + Author: christine@netscape.com 1.28 + Date: 12 november 1997 1.29 +*/ 1.30 + 1.31 +var SECTION = "15.5.4.11-2"; 1.32 +var VERSION = "ECMA_1"; 1.33 +startTest(); 1.34 +var TITLE = "String.prototype.toLowerCase()"; 1.35 + 1.36 +writeHeaderToLog( SECTION + " "+ TITLE); 1.37 + 1.38 +// Hiragana (no upper / lower case) 1.39 +// Range: U+3040 to U+309F 1.40 + 1.41 +for ( var i = 0x3040; i <= 0x309F; i++ ) { 1.42 + var U = new Unicode( i ); 1.43 +/* 1.44 + new TestCase( SECTION, 1.45 + "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()", 1.46 + String.fromCharCode(U.lower), 1.47 + eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") ); 1.48 +*/ 1.49 + new TestCase( SECTION, 1.50 + "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)", 1.51 + U.lower, 1.52 + eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") ); 1.53 +} 1.54 + 1.55 +test(); 1.56 + 1.57 +function MyObject( value ) { 1.58 + this.value = value; 1.59 + this.substring = String.prototype.substring; 1.60 + this.toString = new Function ( "return this.value+''" ); 1.61 +} 1.62 +function Unicode( c ) { 1.63 + this.upper = c; 1.64 + this.lower = c; 1.65 + 1.66 + // upper case Basic Latin 1.67 + 1.68 + if ( c >= 0x0041 && c <= 0x005A) { 1.69 + this.upper = c; 1.70 + this.lower = c + 32; 1.71 + return this; 1.72 + } 1.73 + 1.74 + // lower case Basic Latin 1.75 + if ( c >= 0x0061 && c <= 0x007a ) { 1.76 + this.upper = c - 32; 1.77 + this.lower = c; 1.78 + return this; 1.79 + } 1.80 + 1.81 + // upper case Latin-1 Supplement 1.82 + if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) { 1.83 + this.upper = c; 1.84 + this.lower = c + 32; 1.85 + return this; 1.86 + } 1.87 + 1.88 + // lower case Latin-1 Supplement 1.89 + if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) { 1.90 + this.upper = c - 32; 1.91 + this.lower = c; 1.92 + return this; 1.93 + } 1.94 + if ( c == 0x00FF ) { 1.95 + this.upper = 0x0178; 1.96 + this.lower = c; 1.97 + return this; 1.98 + } 1.99 + // Latin Extended A 1.100 + if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) { 1.101 + // special case for capital I 1.102 + if ( c == 0x0130 ) { 1.103 + this.upper = c; 1.104 + this.lower = 0x0069; 1.105 + return this; 1.106 + } 1.107 + if ( c == 0x0131 ) { 1.108 + this.upper = 0x0049; 1.109 + this.lower = c; 1.110 + return this; 1.111 + } 1.112 + 1.113 + if ( c % 2 == 0 ) { 1.114 + // if it's even, it's a capital and the lower case is c +1 1.115 + this.upper = c; 1.116 + this.lower = c+1; 1.117 + } else { 1.118 + // if it's odd, it's a lower case and upper case is c-1 1.119 + this.upper = c-1; 1.120 + this.lower = c; 1.121 + } 1.122 + return this; 1.123 + } 1.124 + if ( c == 0x0178 ) { 1.125 + this.upper = c; 1.126 + this.lower = 0x00FF; 1.127 + return this; 1.128 + } 1.129 + 1.130 + if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) { 1.131 + if ( c % 2 == 1 ) { 1.132 + // if it's odd, it's a capital and the lower case is c +1 1.133 + this.upper = c; 1.134 + this.lower = c+1; 1.135 + } else { 1.136 + // if it's even, it's a lower case and upper case is c-1 1.137 + this.upper = c-1; 1.138 + this.lower = c; 1.139 + } 1.140 + return this; 1.141 + } 1.142 + if ( c == 0x017F ) { 1.143 + this.upper = 0x0053; 1.144 + this.lower = c; 1.145 + } 1.146 + 1.147 + // Latin Extended B 1.148 + // need to improve this set 1.149 + 1.150 + if ( c >= 0x0200 && c <= 0x0217 ) { 1.151 + if ( c % 2 == 0 ) { 1.152 + this.upper = c; 1.153 + this.lower = c+1; 1.154 + } else { 1.155 + this.upper = c-1; 1.156 + this.lower = c; 1.157 + } 1.158 + return this; 1.159 + } 1.160 + 1.161 + // Latin Extended Additional 1.162 + // Range: U+1E00 to U+1EFF 1.163 + // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html 1.164 + 1.165 + // Spacing Modifier Leters 1.166 + // Range: U+02B0 to U+02FF 1.167 + 1.168 + // Combining Diacritical Marks 1.169 + // Range: U+0300 to U+036F 1.170 + 1.171 + // skip Greek for now 1.172 + // Greek 1.173 + // Range: U+0370 to U+03FF 1.174 + 1.175 + // Cyrillic 1.176 + // Range: U+0400 to U+04FF 1.177 + 1.178 + if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) { 1.179 + this.upper = c; 1.180 + this.lower = c + 80; 1.181 + return this; 1.182 + } 1.183 + 1.184 + 1.185 + if ( c >= 0x0410 && c <= 0x042F ) { 1.186 + this.upper = c; 1.187 + this.lower = c + 32; 1.188 + return this; 1.189 + } 1.190 + 1.191 + if ( c >= 0x0430 && c<= 0x044F ) { 1.192 + this.upper = c - 32; 1.193 + this.lower = c; 1.194 + return this; 1.195 + 1.196 + } 1.197 + if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) { 1.198 + this.upper = c -80; 1.199 + this.lower = c; 1.200 + return this; 1.201 + } 1.202 + 1.203 + if ( c >= 0x0460 && c <= 0x047F ) { 1.204 + if ( c % 2 == 0 ) { 1.205 + this.upper = c; 1.206 + this.lower = c +1; 1.207 + } else { 1.208 + this.upper = c - 1; 1.209 + this.lower = c; 1.210 + } 1.211 + return this; 1.212 + } 1.213 + 1.214 + // Armenian 1.215 + // Range: U+0530 to U+058F 1.216 + if ( c >= 0x0531 && c <= 0x0556 ) { 1.217 + this.upper = c; 1.218 + this.lower = c + 48; 1.219 + return this; 1.220 + } 1.221 + if ( c >= 0x0561 && c < 0x0587 ) { 1.222 + this.upper = c - 48; 1.223 + this.lower = c; 1.224 + return this; 1.225 + } 1.226 + 1.227 + // Hebrew 1.228 + // Range: U+0590 to U+05FF 1.229 + 1.230 + 1.231 + // Arabic 1.232 + // Range: U+0600 to U+06FF 1.233 + 1.234 + // Devanagari 1.235 + // Range: U+0900 to U+097F 1.236 + 1.237 + 1.238 + // Bengali 1.239 + // Range: U+0980 to U+09FF 1.240 + 1.241 + 1.242 + // Gurmukhi 1.243 + // Range: U+0A00 to U+0A7F 1.244 + 1.245 + 1.246 + // Gujarati 1.247 + // Range: U+0A80 to U+0AFF 1.248 + 1.249 + 1.250 + // Oriya 1.251 + // Range: U+0B00 to U+0B7F 1.252 + // no capital / lower case 1.253 + 1.254 + 1.255 + // Tamil 1.256 + // Range: U+0B80 to U+0BFF 1.257 + // no capital / lower case 1.258 + 1.259 + 1.260 + // Telugu 1.261 + // Range: U+0C00 to U+0C7F 1.262 + // no capital / lower case 1.263 + 1.264 + 1.265 + // Kannada 1.266 + // Range: U+0C80 to U+0CFF 1.267 + // no capital / lower case 1.268 + 1.269 + 1.270 + // Malayalam 1.271 + // Range: U+0D00 to U+0D7F 1.272 + 1.273 + // Thai 1.274 + // Range: U+0E00 to U+0E7F 1.275 + 1.276 + 1.277 + // Lao 1.278 + // Range: U+0E80 to U+0EFF 1.279 + 1.280 + 1.281 + // Tibetan 1.282 + // Range: U+0F00 to U+0FBF 1.283 + 1.284 + // Georgian 1.285 + // Range: U+10A0 to U+10F0 1.286 + if ( c >= 0x10A0 && c <= 0x10C5 ) { 1.287 + this.upper = c; 1.288 + this.lower = c + 48; 1.289 + return this; 1.290 + } 1.291 + if ( c >= 0x10D0 && c <= 0x10F5 ) { 1.292 + this.upper = c; 1.293 + this.lower = c; 1.294 + return this; 1.295 + } 1.296 + 1.297 + // Hangul Jamo 1.298 + // Range: U+1100 to U+11FF 1.299 + 1.300 + // Greek Extended 1.301 + // Range: U+1F00 to U+1FFF 1.302 + // skip for now 1.303 + 1.304 + 1.305 + // General Punctuation 1.306 + // Range: U+2000 to U+206F 1.307 + 1.308 + // Superscripts and Subscripts 1.309 + // Range: U+2070 to U+209F 1.310 + 1.311 + // Currency Symbols 1.312 + // Range: U+20A0 to U+20CF 1.313 + 1.314 + 1.315 + // Combining Diacritical Marks for Symbols 1.316 + // Range: U+20D0 to U+20FF 1.317 + // skip for now 1.318 + 1.319 + 1.320 + // Number Forms 1.321 + // Range: U+2150 to U+218F 1.322 + // skip for now 1.323 + 1.324 + 1.325 + // Arrows 1.326 + // Range: U+2190 to U+21FF 1.327 + 1.328 + // Mathematical Operators 1.329 + // Range: U+2200 to U+22FF 1.330 + 1.331 + // Miscellaneous Technical 1.332 + // Range: U+2300 to U+23FF 1.333 + 1.334 + // Control Pictures 1.335 + // Range: U+2400 to U+243F 1.336 + 1.337 + // Optical Character Recognition 1.338 + // Range: U+2440 to U+245F 1.339 + 1.340 + // Enclosed Alphanumerics 1.341 + // Range: U+2460 to U+24FF 1.342 + 1.343 + // Box Drawing 1.344 + // Range: U+2500 to U+257F 1.345 + 1.346 + // Block Elements 1.347 + // Range: U+2580 to U+259F 1.348 + 1.349 + // Geometric Shapes 1.350 + // Range: U+25A0 to U+25FF 1.351 + 1.352 + // Miscellaneous Symbols 1.353 + // Range: U+2600 to U+26FF 1.354 + 1.355 + // Dingbats 1.356 + // Range: U+2700 to U+27BF 1.357 + 1.358 + // CJK Symbols and Punctuation 1.359 + // Range: U+3000 to U+303F 1.360 + 1.361 + // Hiragana 1.362 + // Range: U+3040 to U+309F 1.363 + 1.364 + // Katakana 1.365 + // Range: U+30A0 to U+30FF 1.366 + 1.367 + // Bopomofo 1.368 + // Range: U+3100 to U+312F 1.369 + 1.370 + // Hangul Compatibility Jamo 1.371 + // Range: U+3130 to U+318F 1.372 + 1.373 + // Kanbun 1.374 + // Range: U+3190 to U+319F 1.375 + 1.376 + 1.377 + // Enclosed CJK Letters and Months 1.378 + // Range: U+3200 to U+32FF 1.379 + 1.380 + // CJK Compatibility 1.381 + // Range: U+3300 to U+33FF 1.382 + 1.383 + // Hangul Syllables 1.384 + // Range: U+AC00 to U+D7A3 1.385 + 1.386 + // High Surrogates 1.387 + // Range: U+D800 to U+DB7F 1.388 + 1.389 + // Private Use High Surrogates 1.390 + // Range: U+DB80 to U+DBFF 1.391 + 1.392 + // Low Surrogates 1.393 + // Range: U+DC00 to U+DFFF 1.394 + 1.395 + // Private Use Area 1.396 + // Range: U+E000 to U+F8FF 1.397 + 1.398 + // CJK Compatibility Ideographs 1.399 + // Range: U+F900 to U+FAFF 1.400 + 1.401 + // Alphabetic Presentation Forms 1.402 + // Range: U+FB00 to U+FB4F 1.403 + 1.404 + // Arabic Presentation Forms-A 1.405 + // Range: U+FB50 to U+FDFF 1.406 + 1.407 + // Combining Half Marks 1.408 + // Range: U+FE20 to U+FE2F 1.409 + 1.410 + // CJK Compatibility Forms 1.411 + // Range: U+FE30 to U+FE4F 1.412 + 1.413 + // Small Form Variants 1.414 + // Range: U+FE50 to U+FE6F 1.415 + 1.416 + // Arabic Presentation Forms-B 1.417 + // Range: U+FE70 to U+FEFF 1.418 + 1.419 + // Halfwidth and Fullwidth Forms 1.420 + // Range: U+FF00 to U+FFEF 1.421 + 1.422 + if ( c >= 0xFF21 && c <= 0xFF3A ) { 1.423 + this.upper = c; 1.424 + this.lower = c + 32; 1.425 + return this; 1.426 + } 1.427 + 1.428 + if ( c >= 0xFF41 && c <= 0xFF5A ) { 1.429 + this.upper = c - 32; 1.430 + this.lower = c; 1.431 + return this; 1.432 + } 1.433 + 1.434 + // Specials 1.435 + // Range: U+FFF0 to U+FFFF 1.436 + 1.437 + return this; 1.438 +} 1.439 + 1.440 +function DecimalToHexString( n ) { 1.441 + n = Number( n ); 1.442 + var h = "0x"; 1.443 + 1.444 + for ( var i = 3; i >= 0; i-- ) { 1.445 + if ( n >= Math.pow(16, i) ){ 1.446 + var t = Math.floor( n / Math.pow(16, i)); 1.447 + n -= t * Math.pow(16, i); 1.448 + if ( t >= 10 ) { 1.449 + if ( t == 10 ) { 1.450 + h += "A"; 1.451 + } 1.452 + if ( t == 11 ) { 1.453 + h += "B"; 1.454 + } 1.455 + if ( t == 12 ) { 1.456 + h += "C"; 1.457 + } 1.458 + if ( t == 13 ) { 1.459 + h += "D"; 1.460 + } 1.461 + if ( t == 14 ) { 1.462 + h += "E"; 1.463 + } 1.464 + if ( t == 15 ) { 1.465 + h += "F"; 1.466 + } 1.467 + } else { 1.468 + h += String( t ); 1.469 + } 1.470 + } else { 1.471 + h += "0"; 1.472 + } 1.473 + } 1.474 + 1.475 + return h; 1.476 +}