From a46aecc12a193ce3e48ab278c4a2bde0bd255436 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 19 Jan 2022 18:09:40 +0100 Subject: [PATCH] Test PlainDate.from with more objects. --- ...t-object.js => argument-object-invalid.js} | 30 ++++++++++++++--- .../PlainDate/from/argument-object-valid.js | 33 +++++++++++++++++++ 2 files changed, 58 insertions(+), 5 deletions(-) rename test/built-ins/Temporal/PlainDate/from/{argument-object.js => argument-object-invalid.js} (50%) create mode 100644 test/built-ins/Temporal/PlainDate/from/argument-object-valid.js diff --git a/test/built-ins/Temporal/PlainDate/from/argument-object.js b/test/built-ins/Temporal/PlainDate/from/argument-object-invalid.js similarity index 50% rename from test/built-ins/Temporal/PlainDate/from/argument-object.js rename to test/built-ins/Temporal/PlainDate/from/argument-object-invalid.js index 1afc8dad63..349590473d 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-object.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-object-invalid.js @@ -4,14 +4,10 @@ /*--- esid: sec-temporal.plaindate.from description: Property bag is correctly converted into PlainDate -includes: [compareArray.js, temporalHelpers.js] +includes: [temporalHelpers.js] 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"); @@ -19,3 +15,27 @@ TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(badFields), 2019, 1, "M01", 31, "bad fields with missing overflow"); TemporalHelpers.assertPlainDate(Temporal.PlainDate.from(badFields, { overflow: "constrain" }), 2019, 1, "M01", 31, "bad fields with constrain"); + +assert.throws(RangeError, + () => Temporal.PlainDate.from({ year: 1976, month: 11, monthCode: "M12", day: 18 }), + "month and monthCode must agree"); + +assert.throws(TypeError, + () => Temporal.PlainDate.from({ year: 2019, day: 15 }), + "missing month"); + +assert.throws(TypeError, + () => Temporal.PlainDate.from({}), + "no properties"); + +assert.throws(TypeError, + () => Temporal.PlainDate.from({ month: 12 }), + "missing year, day"); + +assert.throws(TypeError, + () => Temporal.PlainDate.from({ year: 1976, months: 11, day: 18 }), + "misspelled month"); + +assert.throws(TypeError, + () => Temporal.PlainDate.from({ year: undefined, month: 11, day: 18 }), + "year undefined"); diff --git a/test/built-ins/Temporal/PlainDate/from/argument-object-valid.js b/test/built-ins/Temporal/PlainDate/from/argument-object-valid.js new file mode 100644 index 0000000000..e399c247ff --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-object-valid.js @@ -0,0 +1,33 @@ +// Copyright (C) 2022 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: Property bag is correctly converted into PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const valid = [ + [ + { year: 2019, month: 10, monthCode: "M10", day: 1, hour: 14, minute: 20, second: 36 }, + 2019, 10, "M10", 1 + ], + [ + { year: 1976, month: 11, day: 18 }, + 1976, 11, "M11", 18 + ], + [ + { year: 1976, monthCode: "M11", day: 18 }, + 1976, 11, "M11", 18 + ], + [ + { year: 1976, month: 11, day: 18, days: 15 }, + 1976, 11, "M11", 18 + ], +]; + +for (const [dateTimeFields, ...expected] of valid) { + const plainDate = Temporal.PlainDate.from(dateTimeFields); + TemporalHelpers.assertPlainDate(plainDate, ...expected, `from(${JSON.stringify(dateTimeFields)}`); +}