toLocaleUpperCase.js (2510B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 // Test language dependent special casing with different language tags. 4 for (let locale of ["lt", "LT", "lt-LT", "lt-u-co-phonebk", "lt-x-lietuva"]) { 5 assertEq("i\u0307".toLocaleUpperCase(locale), "I"); 6 assertEq("i\u0307".toLocaleUpperCase([locale]), "I"); 7 8 // Additional language tags are ignored. 9 assertEq("i\u0307".toLocaleUpperCase([locale, "und"]), "I"); 10 assertEq("i\u0307".toLocaleUpperCase(["und", locale]), "I\u0307"); 11 } 12 13 // Ensure "lti" (Leti) isn't misrecognized as "lt", even though both share the 14 // same prefix. 15 assertEq("i\u0307".toLocaleUpperCase("lti"), "I\u0307"); 16 assertEq("i\u0307".toLocaleUpperCase(["lti"]), "I\u0307"); 17 18 // Language tag is always verified. 19 for (let locale of ["no_locale", "lt-invalid_ext", ["no_locale"], ["en", "no_locale"]]) { 20 // Empty input string. 21 assertThrowsInstanceOf(() => "".toLocaleUpperCase(locale), RangeError); 22 23 // Non-empty input string. 24 assertThrowsInstanceOf(() => "a".toLocaleUpperCase(locale), RangeError); 25 } 26 27 // No locale argument, undefined as locale, and empty array or array-like all 28 // return the same result. Testing with "a/A" because it has only simple case 29 // mappings. 30 assertEq("a".toLocaleUpperCase(), "A"); 31 assertEq("a".toLocaleUpperCase(undefined), "A"); 32 assertEq("a".toLocaleUpperCase([]), "A"); 33 assertEq("a".toLocaleUpperCase({}), "A"); 34 assertEq("a".toLocaleUpperCase({length: 0}), "A"); 35 assertEq("a".toLocaleUpperCase({length: -1}), "A"); 36 37 // Test with incorrect locale type. 38 for (let locale of [null, 0, Math.PI, NaN, Infinity, true, false, Symbol()]) { 39 // Empty input string. 40 assertThrowsInstanceOf(() => "".toLocaleUpperCase([locale]), TypeError); 41 42 // Non-empty input string. 43 assertThrowsInstanceOf(() => "a".toLocaleUpperCase([locale]), TypeError); 44 } 45 46 // Primitives are converted with ToObject and then queried for .length property. 47 for (let locale of [null]) { 48 // Empty input string. 49 assertThrowsInstanceOf(() => "".toLocaleUpperCase([locale]), TypeError); 50 51 // Non-empty input string. 52 assertThrowsInstanceOf(() => "a".toLocaleUpperCase([locale]), TypeError); 53 } 54 // ToLength(ToObject(<primitive>)) returns 0. 55 for (let locale of [0, Math.PI, NaN, Infinity, true, false, Symbol()]) { 56 // Empty input string. 57 assertEq("".toLocaleUpperCase(locale), ""); 58 59 // Non-empty input string. 60 assertEq("a".toLocaleUpperCase(locale), "A"); 61 } 62 63 if (typeof reportCompare === "function") 64 reportCompare(0, 0, "ok");