From e6b73236145c199731f3d8be026be8080699e616 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 13 Jun 2022 12:34:16 +0200 Subject: [PATCH] Temporal: Extend tests for PlainDate#toPlainYearMonth. --- .../prototype/toPlainYearMonth/basic.js | 15 ++++++++ .../calendar-invalid-return.js | 36 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/basic.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/basic.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/basic.js new file mode 100644 index 0000000000..1a8bb523fb --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/basic.js @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js new file mode 100644 index 0000000000..d7d5a1e5b8 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth/calendar-invalid-return.js @@ -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}`); +}