tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

toLocaleLowerCase.js (2532B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 // Test language dependent special casing with different language tags.
      4 for (let locale of ["tr", "TR", "tr-TR", "tr-u-co-search", "tr-x-turkish"]) {
      5    assertEq("\u0130".toLocaleLowerCase(locale), "i");
      6    assertEq("\u0130".toLocaleLowerCase([locale]), "i");
      7 
      8    // Additional language tags are ignored.
      9    assertEq("\u0130".toLocaleLowerCase([locale, "und"]), "i");
     10    assertEq("\u0130".toLocaleLowerCase(["und", locale]), "\u0069\u0307");
     11 }
     12 
     13 // Ensure "trl" (Traveller Scottish) isn't misrecognized as "tr", even though
     14 // both share the same prefix.
     15 assertEq("\u0130".toLocaleLowerCase("trl"), "\u0069\u0307");
     16 assertEq("\u0130".toLocaleLowerCase(["trl"]), "\u0069\u0307");
     17 
     18 // Language tag is always verified.
     19 for (let locale of ["no_locale", "tr-invalid_ext", ["no_locale"], ["en", "no_locale"]]) {
     20    // Empty input string.
     21    assertThrowsInstanceOf(() => "".toLocaleLowerCase(locale), RangeError);
     22 
     23    // Non-empty input string.
     24    assertThrowsInstanceOf(() => "x".toLocaleLowerCase(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".toLocaleLowerCase(), "a");
     31 assertEq("A".toLocaleLowerCase(undefined), "a");
     32 assertEq("A".toLocaleLowerCase([]), "a");
     33 assertEq("A".toLocaleLowerCase({}), "a");
     34 assertEq("A".toLocaleLowerCase({length: 0}), "a");
     35 assertEq("A".toLocaleLowerCase({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(() => "".toLocaleLowerCase([locale]), TypeError);
     41 
     42    // Non-empty input string.
     43    assertThrowsInstanceOf(() => "A".toLocaleLowerCase([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(() => "".toLocaleLowerCase([locale]), TypeError);
     50 
     51    // Non-empty input string.
     52    assertThrowsInstanceOf(() => "A".toLocaleLowerCase([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("".toLocaleLowerCase(locale), "");
     58 
     59    // Non-empty input string.
     60    assertEq("A".toLocaleLowerCase(locale), "a");
     61 }
     62 
     63 if (typeof reportCompare === "function")
     64    reportCompare(0, 0, "ok");