From 3812a1fe92da51ac99e29400a32e261d3f5ab9c5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 13 Jun 2022 11:54:22 +0200 Subject: [PATCH] Temporal: Extend tests for PlainDate#toString. --- .../prototype/toString/calendar-tostring.js | 28 +++++++++++++++++++ .../prototype/toString/calendarname-always.js | 13 +++++---- .../prototype/toString/calendarname-auto.js | 13 +++++---- .../toString/calendarname-invalid-string.js | 2 +- .../prototype/toString/calendarname-never.js | 13 +++++---- .../toString/calendarname-undefined.js | 13 +++++---- 6 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js new file mode 100644 index 0000000000..0684a0978c --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js @@ -0,0 +1,28 @@ +// 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.protoype.tostring +description: Should always call 'toString' on the calendar once. +features: [Temporal] +---*/ + +let calls; +const customCalendar = { + toString() { + ++calls; + return "custom"; + } +}; +const date = new Temporal.PlainDate(2000, 5, 2, customCalendar); +[ + ["always", "2000-05-02[u-ca=custom]"], + ["auto", "2000-05-02[u-ca=custom]"], + ["never", "2000-05-02"], + [undefined, "2000-05-02[u-ca=custom]"], +].forEach(([calendarName, expected]) => { + calls = 0; + const result = date.toString({ calendarName }); + assert.sameValue(result, expected, `calendarName = ${calendarName}: expected ${expected}`); + assert.sameValue(calls, 1, `calendarName = ${calendarName}: expected one call to 'toString'`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js index 53bcac40b7..629955a664 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-always.js @@ -7,15 +7,16 @@ description: always value for calendarName option features: [Temporal] ---*/ -const calendar = { +const customCalendar = { toString() { return "custom"; } }; -const date1 = new Temporal.PlainDate(2000, 5, 2); -const date2 = new Temporal.PlainDate(2000, 5, 2, calendar); - +const customISOCalendar = { + toString() { return "iso8601"; } +}; [ - [date1, "2000-05-02[u-ca=iso8601]"], - [date2, "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2), "2000-05-02[u-ca=iso8601]"], + [new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02[u-ca=iso8601]"], ].forEach(([date, expected]) => { const result = date.toString({ calendarName: "always" }); assert.sameValue(result, expected, "expected " + expected); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js index 08ad287d52..7acb8c63c8 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-auto.js @@ -7,15 +7,16 @@ description: auto value for calendarName option features: [Temporal] ---*/ -const calendar = { +const customCalendar = { toString() { return "custom"; } }; -const date1 = new Temporal.PlainDate(2000, 5, 2); -const date2 = new Temporal.PlainDate(2000, 5, 2, calendar); - +const customISOCalendar = { + toString() { return "iso8601"; } +}; [ - [date1, "2000-05-02"], - [date2, "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2), "2000-05-02"], + [new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"], ].forEach(([date, expected]) => { const result = date.toString({ calendarName: "auto" }); assert.sameValue(result, expected, "expected " + expected); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-invalid-string.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-invalid-string.js index bca22e7be7..5491e595bc 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-invalid-string.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-invalid-string.js @@ -15,7 +15,7 @@ features: [Temporal] ---*/ const date = new Temporal.PlainDate(2000, 5, 2); -const values = ["ALWAYS", "sometimes", "other string"]; +const values = ["ALWAYS", "sometimes", "other string", "auto\0"]; for (const calendarName of values) { assert.throws(RangeError, () => date.toString({ calendarName })); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js index a937872d1b..75fe99b99e 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-never.js @@ -7,15 +7,16 @@ description: never value for calendarName option features: [Temporal] ---*/ -const calendar = { +const customCalendar = { toString() { return "custom"; } }; -const date1 = new Temporal.PlainDate(2000, 5, 2); -const date2 = new Temporal.PlainDate(2000, 5, 2, calendar); - +const customISOCalendar = { + toString() { return "iso8601"; } +}; [ - [date1, "2000-05-02"], - [date2, "2000-05-02"], + [new Temporal.PlainDate(2000, 5, 2), "2000-05-02"], + [new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02"], + [new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"], ].forEach(([date, expected]) => { const result = date.toString({ calendarName: "never" }); assert.sameValue(result, expected, "expected " + expected); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js index 0d5e93e787..aa3364c9d3 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js @@ -14,15 +14,16 @@ info: | features: [Temporal] ---*/ -const calendar = { +const customCalendar = { toString() { return "custom"; } }; -const date1 = new Temporal.PlainDate(2000, 5, 2); -const date2 = new Temporal.PlainDate(2000, 5, 2, calendar); - +const customISOCalendar = { + toString() { return "iso8601"; } +}; [ - [date1, "2000-05-02"], - [date2, "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2), "2000-05-02"], + [new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"], + [new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"], ].forEach(([date, expected]) => { const explicit = date.toString({ calendarName: undefined }); assert.sameValue(explicit, expected, "default calendarName option is auto");