tor-browser

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

overflow-constrain.js (5722B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2022 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.plainyearmonth.from
      7 description: Reject value for overflow option
      8 includes: [temporalHelpers.js]
      9 features: [Temporal]
     10 ---*/
     11 
     12 const propertyBag = { year: 2000, month: 13 };
     13 const plainYearMonth = Temporal.PlainYearMonth.from(propertyBag, { overflow: "constrain" });
     14 TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2000, 12, "M12", "default overflow is constrain");
     15 
     16 const opt = { overflow: "constrain" };
     17 
     18 let result = Temporal.PlainYearMonth.from({ year: 2021, month: 1 }, opt);
     19 TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "month 1 with overflow constrain");
     20 result = Temporal.PlainYearMonth.from({ year: 2021, month: 2 }, opt);
     21 TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "month 2 with overflow constrain");
     22 result = Temporal.PlainYearMonth.from({ year: 2021, month: 3 }, opt);
     23 TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "month 3 with overflow constrain");
     24 result = Temporal.PlainYearMonth.from({ year: 2021, month: 4 }, opt);
     25 TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "month 4 with overflow constrain");
     26 result = Temporal.PlainYearMonth.from({ year: 2021, month: 5 }, opt);
     27 TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "month 5 with overflow constrain");
     28 result = Temporal.PlainYearMonth.from({ year: 2021, month: 6 }, opt);
     29 TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "month 6 with overflow constrain");
     30 result = Temporal.PlainYearMonth.from({ year: 2021, month: 7 }, opt);
     31 TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "month 7 with overflow constrain");
     32 result = Temporal.PlainYearMonth.from({ year: 2021, month: 8 }, opt);
     33 TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "month 8 with overflow constrain");
     34 result = Temporal.PlainYearMonth.from({ year: 2021, month: 9 }, opt);
     35 TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "month 9 with overflow constrain");
     36 result = Temporal.PlainYearMonth.from({ year: 2021, month: 10 }, opt);
     37 TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "month 10 with overflow constrain");
     38 result = Temporal.PlainYearMonth.from({ year: 2021, month: 11 }, opt);
     39 TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "month 11 with overflow constrain");
     40 result = Temporal.PlainYearMonth.from({ year: 2021, month: 12 }, opt);
     41 TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 12 with overflow constrain");
     42 
     43 assert.throws(
     44  RangeError,
     45  () => Temporal.PlainYearMonth.from({ year: 2021, month: -99999 }, opt),
     46  "negative month -99999 is out of range even with overflow constrain"
     47 )
     48 assert.throws(
     49  RangeError,
     50  () => Temporal.PlainYearMonth.from({ year: 2021, month: -1 }, opt),
     51  "negative month -1 is out of range even with overflow constrain"
     52 )
     53 assert.throws(
     54  RangeError,
     55  () => Temporal.PlainYearMonth.from({ year: 2021, month: 0 }, opt),
     56  "month zero is out of range even with overflow constrain"
     57 )
     58 
     59 result = Temporal.PlainYearMonth.from({ year: 2021, month: 13 }, opt);
     60 TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 13 is constrained to 12");
     61 result = Temporal.PlainYearMonth.from({ year: 2021, month: 99999 }, opt);
     62 TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "month 99999 is constrained to 12");
     63 
     64 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M01" }, opt);
     65 TemporalHelpers.assertPlainYearMonth(result, 2021, 1, "M01", "monthCode M01 with overflow constrain");
     66 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M02" }, opt);
     67 TemporalHelpers.assertPlainYearMonth(result, 2021, 2, "M02", "monthCode M02 with overflow constrain");
     68 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M03" }, opt);
     69 TemporalHelpers.assertPlainYearMonth(result, 2021, 3, "M03", "monthCode M03 with overflow constrain");
     70 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M04" }, opt);
     71 TemporalHelpers.assertPlainYearMonth(result, 2021, 4, "M04", "monthCode M04 with overflow constrain");
     72 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M05" }, opt);
     73 TemporalHelpers.assertPlainYearMonth(result, 2021, 5, "M05", "monthCode M05 with overflow constrain");
     74 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M06" }, opt);
     75 TemporalHelpers.assertPlainYearMonth(result, 2021, 6, "M06", "monthCode M06 with overflow constrain");
     76 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M07" }, opt);
     77 TemporalHelpers.assertPlainYearMonth(result, 2021, 7, "M07", "monthCode M07 with overflow constrain");
     78 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M08" }, opt);
     79 TemporalHelpers.assertPlainYearMonth(result, 2021, 8, "M08", "monthCode M08 with overflow constrain");
     80 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M09" }, opt);
     81 TemporalHelpers.assertPlainYearMonth(result, 2021, 9, "M09", "monthCode M09 with overflow constrain");
     82 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M10" }, opt);
     83 TemporalHelpers.assertPlainYearMonth(result, 2021, 10, "M10", "monthCode M10 with overflow constrain");
     84 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M11" }, opt);
     85 TemporalHelpers.assertPlainYearMonth(result, 2021, 11, "M11", "monthCode M11 with overflow constrain");
     86 result = Temporal.PlainYearMonth.from({ year: 2021, monthCode: "M12" }, opt);
     87 TemporalHelpers.assertPlainYearMonth(result, 2021, 12, "M12", "monthCode M12 with overflow constrain");
     88 
     89 reportCompare(0, 0);