Debian Codegraph @

rhino/testsrc/tests/ecma/String/15.5.4.11-4.js

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