From c0b3a5f07479b3cec2df9279690dae7027e24498 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 20 Jul 2021 13:10:51 -0700 Subject: [PATCH] Add test for abrupt completion for dateAdd --- .../throw-range-error-from-ToTemporalDate.js | 16 +++++++++++++++ ...row-range-error-from-ToTemporalDuration.js | 16 +++++++++++++++ ...row-range-error-from-ToTemporalOverflow.js | 15 ++++++++++++++ .../throw-type-error-from-GetOptionsObject.js | 20 +++++++++++++++++++ ...row-type-error-from-RequireInternalSlot.js | 17 ++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalOverflow.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-RequireInternalSlot.js diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js new file mode 100644 index 0000000000..a54ed271b2 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDate.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: Temporal.Calendar.prototype.dateAdd should throw from ToTemporalDate. +info: | + ... + 4. Set date to ? ToTemporalDate(date). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, + () => cal.dateAdd("invalid date string", new Temporal.Duration(1)), + "Throw by 4. Set date to ? ToTemporalDate(date)"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js new file mode 100644 index 0000000000..cd0e66a2ba --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalDuration.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: Temporal.Calendar.prototype.dateAdd should throw from ToTemporalDuration. +info: | + ... + 5. Set duration to ? ToTemporalDuration(duration). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, + () => cal.dateAdd("2020-02-03", "invalid duration string"), + "Throw by ToTemporalDuration"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalOverflow.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalOverflow.js new file mode 100644 index 0000000000..04496d121b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-range-error-from-ToTemporalOverflow.js @@ -0,0 +1,15 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: Temporal.Calendar.prototype.dateAdd should throw from ToTemporalOverflow. +info: | + 7. Let overflow be ? ToTemporalOverflow(options). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, + () => cal.dateAdd("2020-02-29", "PT1M", {overflow: "bad value"}), + "Bad value in overflow option should throw RangeError"); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js new file mode 100644 index 0000000000..1c5f6b74ef --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-GetOptionsObject.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: Temporal.Calendar.prototype.dateAdd should throw from GetOptionsObject. +info: | + ... + 6. Set options to ? GetOptionsObject(options). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); +let invalidOptionsList = + [null, "invalid option", 234, 23n, Symbol("foo"), true, false, Infinity]; + +invalidOptionsList.forEach(function(invalidOptions) { + assert.throws(TypeError, + () => cal.dateAdd("2020-02-03", "P1Y", invalidOptions), + "Throw by GetOptionsObject"); +}); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-RequireInternalSlot.js new file mode 100644 index 0000000000..9088b744b6 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/throw-type-error-from-RequireInternalSlot.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: Temporal.Calendar.prototype.dateAdd should throw if calendar does not have required internal slot +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { dateAdd: cal.dateAdd }; +assert.throws(TypeError, + () => badCal.dateAdd("2020-02-29", new Temporal.Duration(1)), + "No [[InitializedTemporalCalendar]]");