Debian Codegraph @

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