js/src/tests/ecma/String/15.5.4.11-1.js

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

mercurial