Debian Codegraph @

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