Temporal: Extend tests for PlainDate#toPlainYearMonth.

This commit is contained in:
Ms2ger 2022-06-13 12:34:16 +02:00 committed by Philip Chimento
parent 3812a1fe92
commit e6b7323614
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,15 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.toplainyearmonth
description: Basic toPlainYearMonth tests.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const pd = new Temporal.PlainDate(1970, 12, 24, calendar);
const pym = pd.toPlainYearMonth();
TemporalHelpers.assertPlainYearMonth(pym, 1970, 12, "M12");
assert.sameValue(pym.calendar, calendar);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaindate.prototype.toplainyearmonth
description: Throw when the returned value is not a PlainYearMonth.
features: [Temporal]
---*/
class CustomCalendar extends Temporal.Calendar {
constructor(value) {
super("iso8601");
this.value = value;
}
yearMonthFromFields() {
return this.value;
}
}
const tests = [
[undefined],
[null, "null"],
[true],
["2000-05"],
[Symbol()],
[200005],
[200005n],
[{}, "plain object"],
[() => {}, "lambda"],
[Temporal.PlainYearMonth, "Temporal.PlainYearMonth"],
[Temporal.PlainYearMonth.prototype, "Temporal.PlainYearMonth.prototype"],
];
for (const [test, description = typeof test] of tests) {
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
assert.throws(TypeError, () => plainDate.toPlainYearMonth(), `Expected error with ${description}`);
}