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