Temporal: Extend tests for PlainDate#toPlainMonthDay.

This commit is contained in:
Ms2ger 2022-06-13 15:56:23 +02:00 committed by Philip Chimento
parent e6b7323614
commit 98b76ef533
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.toplainmonthday
description: Basic toPlainMonthDay tests.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const calendar = new Temporal.Calendar("iso8601");
const pd = new Temporal.PlainDate(1970, 12, 24, calendar);
const pmd = pd.toPlainMonthDay();
TemporalHelpers.assertPlainMonthDay(pmd, "M12", 24);
assert.sameValue(pmd.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.toplainmonthday
description: Throw when the returned value is not a PlainMonthDay.
features: [Temporal]
---*/
class CustomCalendar extends Temporal.Calendar {
constructor(value) {
super("iso8601");
this.value = value;
}
monthDayFromFields() {
return this.value;
}
}
const tests = [
[undefined],
[null, "null"],
[true],
["2000-05"],
[Symbol()],
[200005],
[200005n],
[{}, "plain object"],
[() => {}, "lambda"],
[Temporal.PlainMonthDay, "Temporal.PlainMonthDay"],
[Temporal.PlainMonthDay.prototype, "Temporal.PlainMonthDay.prototype"],
];
for (const [test, description = typeof test] of tests) {
const plainDate = new Temporal.PlainDate(2000, 5, 2, new CustomCalendar(test));
assert.throws(TypeError, () => plainDate.toPlainMonthDay(), `Expected error with ${description}`);
}