tor-browser

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

time-separator.js (3589B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Intl')||!Intl.hasOwnProperty("DurationFormat"))
      2 
      3 const {
      4  Integer, Literal, Unit
      5 } = NumberFormatParts;
      6 
      7 const {
      8  Hour, Minute, Second
      9 } = DurationFormatParts;
     10 
     11 const tests = {
     12  "en": [
     13    {
     14      options: {
     15        hours: "2-digit",
     16      },
     17      data: [
     18        {
     19          duration: {hours: 1, minutes: 0},
     20          expected: [
     21            ...Hour(Integer("01")),
     22            Literal(":"),
     23            ...Minute(Integer("00")),
     24            Literal(":"),
     25            ...Second(Integer("00")),
     26          ],
     27        },
     28        {
     29          duration: {hours: 1, minutes: 2},
     30          expected: [
     31            ...Hour(Integer("01")),
     32            Literal(":"),
     33            ...Minute(Integer("02")),
     34            Literal(":"),
     35            ...Second(Integer("00")),
     36          ],
     37        },
     38      ],
     39    },
     40  ],
     41  "da": [
     42    {
     43      options: {
     44        hours: "2-digit",
     45      },
     46      data: [
     47        {
     48          duration: {hours: 1, minutes: 0},
     49          expected: [
     50            ...Hour(Integer("01")),
     51            Literal("."),
     52            ...Minute(Integer("00")),
     53            Literal("."),
     54            ...Second(Integer("00")),
     55          ],
     56        },
     57        {
     58          duration: {hours: 1, minutes: 2},
     59          expected: [
     60            ...Hour(Integer("01")),
     61            Literal("."),
     62            ...Minute(Integer("02")),
     63            Literal("."),
     64            ...Second(Integer("00")),
     65          ],
     66        },
     67      ],
     68    },
     69  ],
     70  "da-u-nu-arabext": [
     71    {
     72      options: {
     73        hours: "2-digit",
     74      },
     75      data: [
     76        {
     77          duration: {hours: 1, minutes: 0},
     78          expected: [
     79            ...Hour(Integer("۰۱")),
     80            Literal("٫"),
     81            ...Minute(Integer("۰۰")),
     82            Literal("٫"),
     83            ...Second(Integer("۰۰")),
     84          ],
     85        },
     86        {
     87          duration: {hours: 1, minutes: 2},
     88          expected: [
     89            ...Hour(Integer("۰۱")),
     90            Literal("٫"),
     91            ...Minute(Integer("۰۲")),
     92            Literal("٫"),
     93            ...Second(Integer("۰۰")),
     94          ],
     95        },
     96      ],
     97    },
     98  ],
     99  "ur-IN": [
    100    {
    101      options: {
    102        hours: "2-digit",
    103      },
    104      data: [
    105        {
    106          duration: {hours: 1, minutes: 0},
    107          expected: [
    108            ...Hour(Integer("۰۱")),
    109            Literal("٫"),
    110            ...Minute(Integer("۰۰")),
    111            Literal("٫"),
    112            ...Second(Integer("۰۰")),
    113          ],
    114        },
    115        {
    116          duration: {hours: 1, minutes: 2},
    117          expected: [
    118            ...Hour(Integer("۰۱")),
    119            Literal("٫"),
    120            ...Minute(Integer("۰۲")),
    121            Literal("٫"),
    122            ...Second(Integer("۰۰")),
    123          ],
    124        },
    125      ],
    126    },
    127  ],
    128 };
    129 
    130 for (let [locale, list] of Object.entries(tests)) {
    131  for (let {options, data} of list) {
    132    let df = new Intl.DurationFormat(locale, options);
    133    for (let {duration, expected} of data) {
    134      let str = PartsToString(expected);
    135 
    136      assertEq(df.format(duration), str,
    137               `${locale} [${JSON.stringify(options)}]: ${JSON.stringify(duration)}`);
    138 
    139      let parts = df.formatToParts(duration);
    140      assertEq(PartsToString(parts), str,
    141               `${locale} [${JSON.stringify(options)}]: ${JSON.stringify(duration)}`);
    142 
    143      assertEq(parts.length, expected.length,
    144               `${locale} [${JSON.stringify(options)}]: ${JSON.stringify(duration)}`);
    145 
    146      assertDeepEq(parts, expected);
    147    }
    148  }
    149 }
    150 
    151 if (typeof reportCompare === "function")
    152  reportCompare(true, true);