tor-browser

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

fields-leap-day.js (2052B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2021 Igalia, S.L. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-temporal.plainmonthday.from
      7 description: Basic tests for PlainMonthDay.from(string).
      8 includes: [compareArray.js, temporalHelpers.js]
      9 features: [Temporal]
     10 ---*/
     11 
     12 // Leap years
     13 ["reject", "constrain"].forEach((overflow) => {
     14  const string = Temporal.PlainMonthDay.from("02-29", { overflow });
     15  TemporalHelpers.assertPlainMonthDay(string, "M02", 29, `from ${overflow} string`);
     16 
     17  const monthCode = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 29 }, { overflow });
     18  TemporalHelpers.assertPlainMonthDay(monthCode, "M02", 29, `from ${overflow} with monthCode`);
     19 
     20  const implicit = Temporal.PlainMonthDay.from({ month: 2, day: 29 }, { overflow });
     21  TemporalHelpers.assertPlainMonthDay(implicit, "M02", 29, `from ${overflow} without year`);
     22 
     23  const explicit = Temporal.PlainMonthDay.from({ month: 2, day: 29, year: 1996 }, { overflow });
     24  TemporalHelpers.assertPlainMonthDay(explicit, "M02", 29, `from ${overflow} with leap year`);
     25 });
     26 
     27 // Non-leap years
     28 assert.throws(RangeError,
     29  () => Temporal.PlainMonthDay.from({ month: 2, day: 29, year: 2001 }, { overflow: "reject" }),
     30  "from reject with non-leap year");
     31 
     32 const nonLeap = Temporal.PlainMonthDay.from({ month: 2, day: 29, year: 2001 }, { overflow: "constrain" });
     33 TemporalHelpers.assertPlainMonthDay(nonLeap, "M02", 28, "from constrain with non-leap year");
     34 
     35 assert.throws(RangeError,
     36  () => Temporal.PlainMonthDay.from({ month: 2, day: 29, year: 2001, calendar: "iso8601" }, { overflow: "reject" }),
     37  "from reject with non-leap year and explicit calendar");
     38 
     39 const nonLeapCalendar = Temporal.PlainMonthDay.from({ month: 2, day: 29, year: 2001, calendar: "iso8601" }, { overflow: "constrain" });
     40 TemporalHelpers.assertPlainMonthDay(nonLeapCalendar, "M02", 28, "from constrain with non-leap year and explicit calendar");
     41 
     42 reportCompare(0, 0);