1// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1.  Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9// 2.  Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24description(
25
26"This test checks that toLowerCase and toUpperCase handle certain non-trivial cases correctly."
27
28);
29
30shouldBe('String("A��").toLowerCase()', '"a��"');
31shouldBe('String("a��").toUpperCase()', '"A��"');
32shouldBe('String("ΚΟΣΜΟΣ ΚΟΣΜΟΣ").toLowerCase()', '"κοσμος κοσμος"');
33shouldBe('String("ß").toUpperCase()', '"SS"');
34shouldBe('String("ʼn").toUpperCase()', '"ʼN"');
35shouldBe('String("ǰ").toUpperCase()', '"J̌"');
36shouldBe('String("ffi").toUpperCase()', '"FFI"');
37shouldBe('String("FFI").toLowerCase()', '"ffi"');
38shouldBe('String("IJ").toLowerCase()', '"ij"');
39
40// Test the toUpper and toLower changes made in Unicode versions 5.2 and 6.1
41// Construct the tests so that it passes if the toLowerCase()/toUpperCase()
42// either return the updated results for compliant platforms or the
43// passed in arguments if not.  This should be changed when all platforms
44// support Unicode 5.2 and Unicode 6.1.
45function createExpected(/* ... */)
46{
47    expected = {};
48
49    for (var i = 0; i < arguments.length; i++) {
50        var s = String.fromCharCode(arguments[i]);
51        expected[s] = true;
52    }
53
54    return expected;
55}
56
57// Check Unicode additions in version 5.2.  From UnicodeData.txt:
58// 0265;LATIN SMALL LETTER TURNED H;Ll;0;L;;;;;N;;;A78D;;A78D
59// A78D;LATIN CAPITAL LETTER TURNED H;Lu;0;L;;;;;N;;;;0265;
60
61var expected = createExpected(0xA78D, 0x0265);
62shouldBeTrue('expected[String.fromCharCode(0xA78D).toLowerCase()]');
63shouldBeTrue('expected[String.fromCharCode(0x0265).toUpperCase()]');
64
65// Check Unicode additions in version 6.1 From UnicodeData.txt:
66// 0266;LATIN SMALL LETTER H WITH HOOK;Ll;0;L;;;;;N;LATIN SMALL LETTER H HOOK;;A7AA;;A7AA
67// 10C7;GEORGIAN CAPITAL LETTER YN;Lu;0;L;;;;;N;;;;2D27;
68// 10CD;GEORGIAN CAPITAL LETTER AEN;Lu;0;L;;;;;N;;;;2D2D;
69// 2CF2;COPTIC CAPITAL LETTER BOHAIRIC KHEI;Lu;0;L;;;;;N;;;;2CF3;
70// 2CF3;COPTIC SMALL LETTER BOHAIRIC KHEI;Ll;0;L;;;;;N;;;2CF2;;2CF2
71// 2D27;GEORGIAN SMALL LETTER YN;Ll;0;L;;;;;N;;;10C7;;10C7
72// 2D2D;GEORGIAN SMALL LETTER AEN;Ll;0;L;;;;;N;;;10CD;;10CD
73// A792;LATIN CAPITAL LETTER C WITH BAR;Lu;0;L;;;;;N;;;;A793;
74// A793;LATIN SMALL LETTER C WITH BAR;Ll;0;L;;;;;N;;;A792;;A792
75// A7AA;LATIN CAPITAL LETTER H WITH HOOK;Lu;0;L;;;;;N;;;;0266;
76
77var expected = createExpected(0x10C7, 0x2D27);
78shouldBeTrue('expected[String.fromCharCode(0x10C7).toLowerCase()]');
79shouldBeTrue('expected[String.fromCharCode(0x2D27).toUpperCase()]');
80
81var expected = createExpected(0x10CD, 0x2D2D);
82shouldBeTrue('expected[String.fromCharCode(0x2D2D).toLowerCase()]');
83shouldBeTrue('expected[String.fromCharCode(0x10CD).toUpperCase()]');
84
85var expected = createExpected(0x2CF2, 0x2CF3);
86shouldBeTrue('expected[String.fromCharCode(0x2CF2).toLowerCase()]');
87shouldBeTrue('expected[String.fromCharCode(0x2CF3).toUpperCase()]');
88
89var expected = createExpected(0xA792, 0xA793);
90shouldBeTrue('expected[String.fromCharCode(0xA792).toLowerCase()]');
91shouldBeTrue('expected[String.fromCharCode(0xA793).toUpperCase()]');
92
93var expected = createExpected(0xA7AA, 0x0266);
94shouldBeTrue('expected[String.fromCharCode(0xA7AA).toLowerCase()]');
95shouldBeTrue('expected[String.fromCharCode(0x0266).toUpperCase()]');
96