From 10a5c4f7849d15fd3a8e65e6e8a4403421596e76 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 29 Jul 2022 15:31:50 -0700 Subject: [PATCH] Temporal: Adjust and expand tests for observable calls to ToString(calendar) This implements the normative change in https://github.com/tc39/proposal-temporal/pull/2269 which reached consensus at the July 2022 TC39 meeting. There was already a test for PlainDate for this topic, which needs to be adjusted to accommodate the normative change. Tests for PlainDateTime and ZonedDateTime did not yet exist, so add new ones based on the PlainDate test. --- .../prototype/toString/calendar-tostring.js | 16 +++++------ .../prototype/toString/calendar-tostring.js | 28 +++++++++++++++++++ .../prototype/toString/calendar-tostring.js | 28 +++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/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 index 0684a0978c4..75a2e03fbf2 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.plaindate.protoype.tostring -description: Should always call 'toString' on the calendar once. +description: Should call 'toString' on the calendar once unless calendarName == 'never'. features: [Temporal] ---*/ @@ -16,13 +16,13 @@ const customCalendar = { }; 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]) => { + ["always", "2000-05-02[u-ca=custom]", 1], + ["auto", "2000-05-02[u-ca=custom]", 1], + ["never", "2000-05-02", 0], + [undefined, "2000-05-02[u-ca=custom]", 1], +].forEach(([calendarName, expectedResult, expectedCalls]) => { 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'`); + assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`); + assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js new file mode 100644 index 00000000000..9ff60128346 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/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.plaindatetime.protoype.tostring +description: Should call 'toString' on the calendar once unless calendarName == 'never'. +features: [Temporal] +---*/ + +let calls; +const customCalendar = { + toString() { + ++calls; + return "custom"; + } +}; +const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, customCalendar); +[ + ["always", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], + ["auto", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], + ["never", "2000-05-02T12:34:56.987654321", 0], + [undefined, "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], +].forEach(([calendarName, expectedResult, expectedCalls]) => { + calls = 0; + const result = date.toString({ calendarName }); + assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`); + assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js new file mode 100644 index 00000000000..d91f9c522b0 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/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.zoneddatetime.protoype.tostring +description: Should call 'toString' on the calendar once unless calendarName == 'never'. +features: [Temporal] +---*/ + +let calls; +const customCalendar = { + toString() { + ++calls; + return "custom"; + } +}; +const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", customCalendar); +[ + ["always", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], + ["auto", "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], + ["never", "1970-01-01T01:01:01.987654321+00:00[UTC]", 0], + [undefined, "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", 1], +].forEach(([calendarName, expectedResult, expectedCalls]) => { + calls = 0; + const result = date.toString({ calendarName }); + assert.sameValue(result, expectedResult, `calendarName = ${calendarName}: expected ${expectedResult}`); + assert.sameValue(calls, expectedCalls, `calendarName = ${calendarName}: expected ${expectedCalls} call(s) to 'toString'`); +});