Add test for abrupt completion for dateAdd

This commit is contained in:
Frank Tang 2021-07-20 13:10:51 -07:00 committed by Rick Waldron
parent 6c077667fc
commit c0b3a5f074
5 changed files with 84 additions and 0 deletions

View File

@ -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)");

View File

@ -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");

View File

@ -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");

View File

@ -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");
});

View File

@ -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]]");