mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Add tests for overflow in PlainDate.from().
This commit is contained in:
parent
aa77abd928
commit
7bfda9f10b
@ -11,3 +11,11 @@ features: [Temporal]
|
|||||||
const dateTimeFields = { year: 2019, month: 10, monthCode: "M10", day: 1, hour: 14, minute: 20, second: 36 };
|
const dateTimeFields = { year: 2019, month: 10, monthCode: "M10", day: 1, hour: 14, minute: 20, second: 36 };
|
||||||
const plainDate = Temporal.PlainDate.from(dateTimeFields);
|
const plainDate = Temporal.PlainDate.from(dateTimeFields);
|
||||||
TemporalHelpers.assertPlainDate(plainDate, 2019, 10, "M10", 1);
|
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");
|
||||||
|
@ -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);
|
@ -5,9 +5,6 @@
|
|||||||
esid: sec-temporal.plaindate.from
|
esid: sec-temporal.plaindate.from
|
||||||
description: overflow property is extracted with string argument.
|
description: overflow property is extracted with string argument.
|
||||||
info: |
|
info: |
|
||||||
1. If Type(_item_) is Object, then
|
|
||||||
1. ...
|
|
||||||
1. Return ? DateFromFields(_calendar_, _fields_, _options_).
|
|
||||||
1. Perform ? ToTemporalOverflow(_options_).
|
1. Perform ? ToTemporalOverflow(_options_).
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
includes: [compareArray.js, temporalHelpers.js]
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
|
@ -22,11 +22,20 @@ info: |
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const validValues = [
|
const validItems = [
|
||||||
new Temporal.PlainDate(2000, 5, 2),
|
new Temporal.PlainDate(2000, 5, 2),
|
||||||
{ year: 2000, month: 5, day: 2 },
|
{ year: 2000, month: 5, day: 2 },
|
||||||
"2000-05-02",
|
"2000-05-02",
|
||||||
];
|
];
|
||||||
validValues.forEach((value) => {
|
const invalidOverflow = [
|
||||||
assert.throws(RangeError, () => Temporal.PlainDate.from(value, { overflow: "other string" }));
|
"",
|
||||||
|
"other string",
|
||||||
|
"balance",
|
||||||
|
"CONSTRAIN",
|
||||||
|
"constra\u0131n",
|
||||||
|
];
|
||||||
|
validItems.forEach((item) => {
|
||||||
|
invalidOverflow.forEach((overflow) => {
|
||||||
|
assert.throws(RangeError, () => Temporal.PlainDate.from(item, { overflow }));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user