Add abstract operation test for dateFromFields

This commit is contained in:
Frank Tang 2021-07-20 13:50:20 -07:00 committed by Rick Waldron
parent c0b3a5f074
commit bf1b3f585f
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// 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]
---*/
let cal = new Temporal.Calendar("iso8601")
assert.throws(RangeError, () => cal.dateFromFields({year: 2021, month: 7, day: 20},
{overflow: "invalid garbage"}),
"RangeError should be throw from ISODateFromFields");

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.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: [Temporal]
---*/
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),
"fields is not object");
})

View File

@ -0,0 +1,18 @@
// 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 from GetOptionsObject.
info: |
4. If Type(fields) is not Object, throw a TypeError exception.
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
let fields = {year: 2021, month: 7, day: 20};
let notObjectList = [
null, "string", Symbol('efg'), true, false, Infinity, NaN, 123, 456n];
notObjectList.forEach(function(options) {
assert.throws(TypeError, () => cal.dateFromFields(fields, options),
"options is not object");
})

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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw TypeError while calendar has no [[InitializedTemporalCalendar]]
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
let badCal = {dateFromFields: cal.dateFromFields};
assert.throws(TypeError, () => badCal.dateFromFields({year: 2021, month: 3, day: 17}),
"calendar has no [[InitializedTemporalCalendar]]");