js/src/tests/ecma/String/15.5.4.12-5.js

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

mercurial