summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/String/toLocaleUpperCase.js
blob: 0a33320dc731f71744026f6ca734ecfdd5b4dd88 (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
58
59
60
61
62
63
64
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

// Test language dependent special casing with different language tags.
for (let locale of ["lt", "LT", "lt-LT", "lt-u-co-phonebk", "lt-x-lietuva"]) {
    assertEq("i\u0307".toLocaleUpperCase(locale), "I");
    assertEq("i\u0307".toLocaleUpperCase([locale]), "I");

    // Additional language tags are ignored.
    assertEq("i\u0307".toLocaleUpperCase([locale, "und"]), "I");
    assertEq("i\u0307".toLocaleUpperCase(["und", locale]), "I\u0307");
}

// Ensure "lti" (Leti) isn't misrecognized as "lt", even though both share the
// same prefix.
assertEq("i\u0307".toLocaleUpperCase("lti"), "I\u0307");
assertEq("i\u0307".toLocaleUpperCase(["lti"]), "I\u0307");

// Language tag is always verified.
for (let locale of ["no_locale", "lt-invalid_ext", ["no_locale"], ["en", "no_locale"]]) {
    // Empty input string.
    assertThrowsInstanceOf(() => "".toLocaleUpperCase(locale), RangeError);

    // Non-empty input string.
    assertThrowsInstanceOf(() => "a".toLocaleUpperCase(locale), RangeError);
}

// No locale argument, undefined as locale, and empty array or array-like all
// return the same result. Testing with "a/A" because it has only simple case
// mappings.
assertEq("a".toLocaleUpperCase(), "A");
assertEq("a".toLocaleUpperCase(undefined), "A");
assertEq("a".toLocaleUpperCase([]), "A");
assertEq("a".toLocaleUpperCase({}), "A");
assertEq("a".toLocaleUpperCase({length: 0}), "A");
assertEq("a".toLocaleUpperCase({length: -1}), "A");

// Test with incorrect locale type.
for (let locale of [null, 0, Math.PI, NaN, Infinity, true, false, Symbol()]) {
    // Empty input string.
    assertThrowsInstanceOf(() => "".toLocaleUpperCase([locale]), TypeError);

    // Non-empty input string.
    assertThrowsInstanceOf(() => "a".toLocaleUpperCase([locale]), TypeError);
}

// Primitives are converted with ToObject and then queried for .length property.
for (let locale of [null]) {
    // Empty input string.
    assertThrowsInstanceOf(() => "".toLocaleUpperCase([locale]), TypeError);

    // Non-empty input string.
    assertThrowsInstanceOf(() => "a".toLocaleUpperCase([locale]), TypeError);
}
// ToLength(ToObject(<primitive>)) returns 0.
for (let locale of [0, Math.PI, NaN, Infinity, true, false, Symbol()]) {
    // Empty input string.
    assertEq("".toLocaleUpperCase(locale), "");

    // Non-empty input string.
    assertEq("a".toLocaleUpperCase(locale), "A");
}

if (typeof reportCompare === "function")
    reportCompare(0, 0, "ok");