summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/latin1/toLowerCase-toUpperCase.js
blob: d1855dc3d7b3576a08083035a5cc5b759ec770d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function testToLowerCase() {
    var s1 = "abcdefgABCDEFGH 123456";
    assertEq(isLatin1(s1), true);

    // Latin1
    var s2 = s1.toLowerCase();
    assertEq(isLatin1(s2), true);
    assertEq(s2, "abcdefgabcdefgh 123456");

    s2 = s1.toLocaleLowerCase();
    assertEq(isLatin1(s2), true);
    assertEq(s2, "abcdefgabcdefgh 123456");

    // TwoByte
    s2 = "abcdefg\u1200ABCDEFGH 123456\u04AC".toLowerCase();
    assertEq(s2, "abcdefg\u1200abcdefgh 123456\u04AD");

    s2 = "abcdefg\u1200ABCDEFGH 123456\u04AC".toLocaleLowerCase();
    assertEq(s2, "abcdefg\u1200abcdefgh 123456\u04AD");

    // For toLowerCase, every Latin1 character maps to a Latin1 character.
    for (var i=0; i <= 0xff; i++) {
	var s = "\u1200\u11AA" + String.fromCharCode(i);
	assertEq(s.toLowerCase().charCodeAt(2) <= 0xff, true);
    }
}
testToLowerCase();

function testToUpperCase() {
    var s1 = "abcdefgABCDEFGH 12345";
    assertEq(isLatin1(s1), true);

    // Latin1
    var s2 = s1.toUpperCase();
    assertEq(isLatin1(s2), true);
    assertEq(s2, "ABCDEFGABCDEFGH 12345");

    s2 = s1.toLocaleUpperCase();
    assertEq(isLatin1(s2), true);
    assertEq(s2, "ABCDEFGABCDEFGH 12345");

    // TwoByte
    s2 = "abcdefg\u1200ABCDEFGH 12345\u1E0F".toUpperCase();
    assertEq(s2, "ABCDEFG\u1200ABCDEFGH 12345\u1E0E");

    s2 = "abcdefg\u1200ABCDEFGH 12345\u1E0F".toLocaleUpperCase();
    assertEq(s2, "ABCDEFG\u1200ABCDEFGH 12345\u1E0E");

    // Tricky case: Latin1 character \u00FF maps to \u0178, a
    // non-Latin1 character.
    s1 = "ABC\u00FF";
    assertEq(isLatin1(s1), true);
    s2 = s1.toUpperCase();
    assertEq(isLatin1(s2), false);
    assertEq(s2, "ABC\u0178");
}
testToUpperCase();