Consolidate duplicate tests

There were a few tests already in the tree that overlapped ones that I
added in the previous commit. I've consolidated these and taken
information from the deleted ones where applicable, and improved on the
autogenerated assertion messages.
This commit is contained in:
Philip Chimento 2021-09-29 13:25:31 -07:00 committed by jugglinmike
parent 77a34cf93f
commit 56e537b916
6 changed files with 17 additions and 55 deletions

View File

@ -11,10 +11,12 @@ info: |
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*).
sec-temporal.calendar.prototype.dateadd step 7:
7. Let _overflow_ be ? ToTemporalOverflow(_options_).
features: [Temporal]
features: [Temporal, arrow-function]
---*/
const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
const duration = new Temporal.Duration(3, 3, 0, 3);
assert.throws(RangeError, () => calendar.dateAdd(date, duration, { overflow: "other string" }));
assert.throws(RangeError,
() => calendar.dateAdd(date, duration, { overflow: "other string" }),
"Value for overflow not one of the allowed string values");

View File

@ -1,15 +0,0 @@
// 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, arrow-function]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.throws(RangeError,
() => cal.dateAdd("2020-02-29", "PT1M", {overflow: "bad value"}),
'cal.dateAdd("2020-02-29", "PT1M", {overflow: "bad value"}) throws a RangeError exception');

View File

@ -4,11 +4,17 @@
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: Throw a TypeError if the fields is not an object
features: [Symbol, Temporal]
info: |
4. If Type(_fields_) is not Object, throw a *TypeError* exception.
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
const tests = [undefined, null, false, "string", Symbol("sym"), Math.PI, 42n];
const tests = [undefined, null, true, false, "string", Symbol("sym"), Infinity, NaN, Math.PI, 42n];
const iso = Temporal.Calendar.from("iso8601");
for (const fields of tests) {
assert.throws(TypeError, () => iso.dateFromFields(fields, {}));
assert.throws(
TypeError,
() => iso.dateFromFields(fields, {})
`dateFromFields(${typeof fields}) throws a TypeError exception`
);
}

View File

@ -13,8 +13,10 @@ info: |
2. Let _overflow_ be ? ToTemporalOverflow(_options_).
sec-temporal.calendar.prototype.datefromfields step 6:
6. Let _result_ be ? ISODateFromFields(_fields_, _options_).
features: [Temporal]
features: [Temporal, arrow-function]
---*/
const calendar = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => calendar.dateFromFields({ year: 2000, month: 5, day: 2 }, { overflow: "other string" }));
assert.throws(RangeError, () => calendar.dateFromFields({ year: 2000, month: 5, day: 2 },
{ overflow: "other string" }),
"Value for overflow not one of the allowed string values");

View File

@ -1,14 +0,0 @@
// 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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw Error from ISODateFromFields.
info: |
6. Let result be ? ISODateFromFields(fields, options).
features: [Temporal, arrow-function]
---*/
let cal = new Temporal.Calendar("iso8601")
assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 7, day: 20},
{overflow: "invalid garbage"}),
'cal.dateFromFields({year: 2021, month: 7, day: 20}, {overflow: "invalid garbage"}) throws a RangeError exception');

View File

@ -1,19 +0,0 @@
// 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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw TypeError while fields is not object.
info: |
4. If Type(fields) is not Object, throw a TypeError exception.
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
let cal = new Temporal.Calendar('iso8601');
let notObjectList = [null, undefined, 'string', Symbol('efg'), true, false, Infinity, NaN, 123, 456n];
notObjectList.forEach(function(fields) {
assert.throws(
TypeError,
() => cal.dateFromFields(fields),
'cal.dateFromFields(fields) throws a TypeError exception'
);
});