tor-browser

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

constructor-options-dayPeriod-valid.js (1138B)


      1 // Copyright 2019 Google Inc. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-createdatetimeformat
      6 description: >
      7  Checks handling of the options argument to the DateTimeFormat constructor.
      8 info: |
      9  [[DayPeriod]]    `"dayPeriod"`    `"narrow"`, `"short"`, `"long"`
     10  CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults )
     11 
     12  ...
     13 features: [Intl.DateTimeFormat-dayPeriod]
     14 ---*/
     15 
     16 const validOptions = [
     17  [undefined, undefined],
     18  ["long", "long"],
     19  ["short", "short"],
     20  ["narrow", "narrow"],
     21  [{ toString() { return "narrow"; } }, "narrow"],
     22  [{ valueOf() { return "long"; }, toString: undefined }, "long"],
     23 ];
     24 for (const [dayPeriod, expected] of validOptions) {
     25  const dtf = new Intl.DateTimeFormat("en", { dayPeriod });
     26  const options = dtf.resolvedOptions();
     27  assert.sameValue(options.dayPeriod, expected);
     28  const propdesc = Object.getOwnPropertyDescriptor(options, "dayPeriod");
     29  if (expected === undefined) {
     30    assert.sameValue(propdesc, undefined);
     31  } else {
     32    assert.sameValue(propdesc.value, expected);
     33  }
     34 }
     35 
     36 reportCompare(0, 0);