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

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

mercurial