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'`); +});