From 7bfda9f10b2eb721a88d45efbcc5ff44003f5c19 Mon Sep 17 00:00:00 2001 From: Ms2ger <Ms2ger@gmail.com> Date: Wed, 29 Dec 2021 10:11:07 +0100 Subject: [PATCH] Add tests for overflow in PlainDate.from(). --- .../PlainDate/from/argument-object.js | 8 +++++ .../PlainDate/from/argument-string-invalid.js | 30 +++++++++++++++++++ .../PlainDate/from/argument-string.js | 3 -- .../PlainDate/from/overflow-invalid-string.js | 15 ++++++++-- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 test/built-ins/Temporal/PlainDate/from/argument-string-invalid.js diff --git a/test/built-ins/Temporal/PlainDate/from/argument-object.js b/test/built-ins/Temporal/PlainDate/from/argument-object.js index 9bed48298f..9b691d3686 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-object.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-object.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainDate/from/argument-string-invalid.js b/test/built-ins/Temporal/PlainDate/from/argument-string-invalid.js new file mode 100644 index 0000000000..f0dee3ade9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-string-invalid.js @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/from/argument-string.js b/test/built-ins/Temporal/PlainDate/from/argument-string.js index 1eee15b7b1..f3af861800 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-string.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-string.js @@ -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] diff --git a/test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js b/test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js index 01f5c913ee..f04f77f745 100644 --- a/test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js +++ b/test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js @@ -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 })); + }); });