From f4367bc3150f5df89cc0e5b939e6aaad459ad667 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 16 Nov 2025 09:58:11 -0800 Subject: [PATCH] Temporal: Expand ISO8601 PlainDate.p.with tests Move coverage of plural units to a separate file, and add some more coverage for the overflow option. --- .../PlainDate/prototype/with/basic.js | 5 -- .../PlainDate/prototype/with/overflow.js | 59 +++++++++++++++++++ .../prototype/with/plural-units-ignored.js | 14 +++++ 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/with/overflow.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/basic.js b/test/built-ins/Temporal/PlainDate/prototype/with/basic.js index ed95391977..a28d24f615 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/with/basic.js +++ b/test/built-ins/Temporal/PlainDate/prototype/with/basic.js @@ -21,8 +21,3 @@ TemporalHelpers.assertPlainDate(withMonthCode, 1976, 5, "M05", 18, "with(monthCo const withDay = plainDate.with({ day: 17 }); TemporalHelpers.assertPlainDate(withDay, 1976, 11, "M11", 17, "with(day)"); - -const withPlural = plainDate.with({ months: 12, day: 15 }); -TemporalHelpers.assertPlainDate(withPlural, 1976, 11, "M11", 15, "with(plural)"); - -assert.throws(RangeError, () => plainDate.with({ month: 5, monthCode: 'M06' })); diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/overflow.js b/test/built-ins/Temporal/PlainDate/prototype/with/overflow.js new file mode 100644 index 0000000000..424fc127a9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/with/overflow.js @@ -0,0 +1,59 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.with +description: Basic tests for the overflow option +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const date = new Temporal.PlainDate(1976, 11, 18); + +assert.throws( + RangeError, + () => date.with({ year: -300000 }), + "too-low year rejects even with overflow constrain"); + +assert.throws( + RangeError, + () => date.with({ year: 300000 }), + "too-high year rejects even with overflow constrain"); + +assert.throws( + RangeError, + () => date.with({ month: 0 }), + "non-positive month rejects even with overflow constrain"); + +TemporalHelpers.assertPlainDate( + date.with({ month: 13 }), + 1976, 12, "M12", 18, + "too-high month is constrained to highest value"); + +assert.throws(RangeError, function () { + date.with({ month: 13 }, { overflow: "reject" }); +}, "too-high month rejects"); + +assert.throws( + RangeError, + () => date.with({ monthCode: "M13" }), + "Invalid monthCode for calendar rejects even with overflow constrain"); + +assert.throws( + RangeError, + () => date.with({ day: 0 }), + "non-positive day rejects even with overflow constrain"); + +TemporalHelpers.assertPlainDate( + date.with({ day: 31 }), + 1976, 11, "M11", 30, + "too-high day is constrained to highest value"); + +assert.throws(RangeError, function () { + date.with({ day: 31 }, { overflow: "reject" }); +}, "too-high day rejects"); + +assert.throws( + RangeError, + () => date.with({ month: 5, monthCode: "M06" }), + "Conflicting month and monthCode rejects even with overflow constrain"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js b/test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js new file mode 100644 index 0000000000..7cc75917a4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.with +description: Plural units are not valid in the property bag +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const plainDate = new Temporal.PlainDate(1976, 11, 18); + +const withPlural = plainDate.with({ months: 12, day: 15 }); +TemporalHelpers.assertPlainDate(withPlural, 1976, 11, "M11", 15, "Plural units in the property bag should ignored");