tor-browser

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

numberingSystem-option.js (2337B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Intl'))
      2 
      3 const defaultLocale = "en";
      4 const defaultNumberingSystem = new Intl.RelativeTimeFormat(defaultLocale).resolvedOptions().numberingSystem;
      5 
      6 function createWithLocale(locale, numberingSystem) {
      7  return new Intl.RelativeTimeFormat(locale, {numberingSystem});
      8 }
      9 
     10 function create(numberingSystem) {
     11  return createWithLocale(defaultLocale, numberingSystem);
     12 }
     13 
     14 // Empty string should throw.
     15 assertThrowsInstanceOf(() => create(""), RangeError);
     16 
     17 // Trailing \0 should throw.
     18 assertThrowsInstanceOf(() => create("latn\0"), RangeError);
     19 
     20 // Too short or too long strings should throw.
     21 assertThrowsInstanceOf(() => create("a"), RangeError);
     22 assertThrowsInstanceOf(() => create("toolongstring"), RangeError);
     23 
     24 // Throw even when prefix is valid.
     25 assertThrowsInstanceOf(() => create("latn-toolongstring"), RangeError);
     26 
     27 // |numberingSystem| can be set to |undefined|.
     28 let nf = create(undefined);
     29 assertEq(nf.resolvedOptions().numberingSystem, defaultNumberingSystem);
     30 
     31 // Unsupported numbering systems are ignored.
     32 nf = create("xxxxxxxx");
     33 assertEq(nf.resolvedOptions().numberingSystem, defaultNumberingSystem);
     34 
     35 // Numbering system in options overwrite Unicode extension keyword.
     36 nf = createWithLocale(`${defaultLocale}-u-nu-thai`, "arab");
     37 assertEq(nf.resolvedOptions().locale, defaultLocale);
     38 assertEq(nf.resolvedOptions().numberingSystem, "arab");
     39 
     40 // |numberingSystem| option ignores case.
     41 nf = create("ARAB");
     42 assertEq(nf.resolvedOptions().locale, defaultLocale);
     43 assertEq(nf.resolvedOptions().numberingSystem, "arab");
     44 
     45 for (let [numberingSystem, {algorithmic}] of Object.entries(numberingSystems)) {
     46  let nf1 = new Intl.RelativeTimeFormat(`${defaultLocale}-u-nu-${numberingSystem}`);
     47  let nf2 = new Intl.RelativeTimeFormat(defaultLocale, {numberingSystem});
     48 
     49  if (!algorithmic) {
     50    assertEq(nf1.resolvedOptions().numberingSystem, numberingSystem);
     51    assertEq(nf2.resolvedOptions().numberingSystem, numberingSystem);
     52  } else {
     53    // We don't yet support algorithmic numbering systems.
     54    assertEq(nf1.resolvedOptions().numberingSystem, defaultNumberingSystem);
     55    assertEq(nf2.resolvedOptions().numberingSystem, defaultNumberingSystem);
     56  }
     57 
     58  assertEq(nf2.format(0, "second"), nf1.format(0, "second"));
     59 }
     60 
     61 if (typeof reportCompare === "function")
     62  reportCompare(true, true);