Debian Codegraph @

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