~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/lang/js/test/ecma/String/15.5.4.11-2.js

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

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