Add tests for overflow in PlainDate.from().

This commit is contained in:
Ms2ger 2021-12-29 10:11:07 +01:00 committed by Rick Waldron
parent aa77abd928
commit 7bfda9f10b
4 changed files with 50 additions and 6 deletions

View File

@ -11,3 +11,11 @@ features: [Temporal]
const dateTimeFields = { year: 2019, month: 10, monthCode: "M10", day: 1, hour: 14, minute: 20, second: 36 };
const plainDate = Temporal.PlainDate.from(dateTimeFields);
TemporalHelpers.assertPlainDate(plainDate, 2019, 10, "M10", 1);
const badFields = { year: 2019, month: 1, day: 32 };
assert.throws(RangeError, () => Temporal.PlainDate.from(badFields, { overflow: "reject" }),
"bad fields with reject");
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(badFields),
plainDate, 2019, 1, "M01", 31, "bad fields with missing overflow");
TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(badFields, { overflow: "constrain" }),
plainDate, 2019, 1, "M01", 31, "bad fields with constrain");

View File

@ -0,0 +1,30 @@
// 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.from
description: overflow property is extracted with ISO-invalid string argument.
info: |
1. Perform ? ToTemporalOverflow(_options_).
1. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"get overflow",
"get overflow.toString",
"call overflow.toString",
];
let actual = [];
const object = {
get overflow() {
actual.push("get overflow");
return TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow");
}
};
assert.throws(RangeError, () => Temporal.PlainDate.from("2020-13-34", object));
assert.compareArray(actual, expected);

View File

@ -5,9 +5,6 @@
esid: sec-temporal.plaindate.from
description: overflow property is extracted with string argument.
info: |
1. If Type(_item_) is Object, then
1. ...
1. Return ? DateFromFields(_calendar_, _fields_, _options_).
1. Perform ? ToTemporalOverflow(_options_).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]

View File

@ -22,11 +22,20 @@ info: |
features: [Temporal]
---*/
const validValues = [
const validItems = [
new Temporal.PlainDate(2000, 5, 2),
{ year: 2000, month: 5, day: 2 },
"2000-05-02",
];
validValues.forEach((value) => {
assert.throws(RangeError, () => Temporal.PlainDate.from(value, { overflow: "other string" }));
const invalidOverflow = [
"",
"other string",
"balance",
"CONSTRAIN",
"constra\u0131n",
];
validItems.forEach((item) => {
invalidOverflow.forEach((overflow) => {
assert.throws(RangeError, () => Temporal.PlainDate.from(item, { overflow }));
});
});