From 516f9a90831569b7b1d3e310dcf9331df1c0c82c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 1 Feb 2022 16:18:33 +0100 Subject: [PATCH] Test PlainYearMonth.prototype.toString. --- .../prototype/toString/calendarname-always.js | 22 +++++++++++++++++++ .../prototype/toString/calendarname-auto.js | 22 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 4 +++- .../prototype/toString/calendarname-never.js | 22 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..d6fa52e106 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-always.js @@ -0,0 +1,22 @@ +// 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.plainyearmonth.protoype.tostring +description: always value for calendarName option +features: [Temporal] +---*/ + +const calendar = { + toString() { return "custom"; } +}; +const yearmonth1 = new Temporal.PlainYearMonth(2000, 5); +const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar); + +[ + [yearmonth1, "2000-05[u-ca=iso8601]"], + [yearmonth2, "2000-05-01[u-ca=custom]"], +].forEach(([yearmonth, expected]) => { + const result = yearmonth.toString({ calendarName: "always" }); + assert.sameValue(result, expected, "calendarName is always"); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..3aa15bac39 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-auto.js @@ -0,0 +1,22 @@ +// 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.plainyearmonth.protoype.tostring +description: auto value for calendarName option +features: [Temporal] +---*/ + +const calendar = { + toString() { return "custom"; } +}; +const yearmonth1 = new Temporal.PlainYearMonth(2000, 5); +const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar); + +[ + [yearmonth1, "2000-05"], + [yearmonth2, "2000-05-01[u-ca=custom]"], +].forEach(([yearmonth, expected]) => { + const result = yearmonth.toString({ calendarName: "auto" }); + assert.sameValue(result, expected, "calendarName is auto"); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-invalid-string.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-invalid-string.js index e1b8b71025..23f0ffc9c5 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-invalid-string.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-invalid-string.js @@ -15,4 +15,6 @@ features: [Temporal] ---*/ const yearmonth = new Temporal.PlainYearMonth(2000, 5); -assert.throws(RangeError, () => yearmonth.toString({ calendarName: "other string" })); +for (const calendarName of ["ALWAYS", "sometimes", "other string"]) { + assert.throws(RangeError, () => yearmonth.toString({ calendarName })); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..e7dd619b9f --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-never.js @@ -0,0 +1,22 @@ +// 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.plainyearmonth.protoype.tostring +description: never value for calendarName option +features: [Temporal] +---*/ + +const calendar = { + toString() { return "custom"; } +}; +const yearmonth1 = new Temporal.PlainYearMonth(2000, 5); +const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar); + +[ + [yearmonth1, "2000-05"], + [yearmonth2, "2000-05-01"], +].forEach(([yearmonth, expected]) => { + const result = yearmonth.toString({ calendarName: "never" }); + assert.sameValue(result, expected, "calendarName is never"); +});