mirror of
https://github.com/tc39/test262.git
synced 2025-11-17 12:19:49 +01:00
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.
This commit is contained in:
parent
2f0cc98718
commit
f4367bc315
@ -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' }));
|
||||
|
||||
59
test/built-ins/Temporal/PlainDate/prototype/with/overflow.js
vendored
Normal file
59
test/built-ins/Temporal/PlainDate/prototype/with/overflow.js
vendored
Normal file
@ -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");
|
||||
14
test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js
vendored
Normal file
14
test/built-ins/Temporal/PlainDate/prototype/with/plural-units-ignored.js
vendored
Normal file
@ -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");
|
||||
Loading…
x
Reference in New Issue
Block a user