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

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

mercurial