diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..5ae257d8bd --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js @@ -0,0 +1,16 @@ +// 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.prototype.tostring +description: Show ISO calendar if calendar name is "always" +features: [Temporal] +---*/ + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +assert.sameValue( + dt.toString({ calendarName: "always" }), + "1976-11-18T15:23:00[u-ca=iso8601]", + "shows ISO calendar if calendarName = always" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..7440f54922 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js @@ -0,0 +1,35 @@ +// 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.prototype.tostring +description: Possibly display calendar when calendarName is "auto" +features: [Temporal] +---*/ + + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); +const customCal = { + toString() { return "bogus"; } +}; +const fakeISO8601Cal = { + toString() { return "iso8601"; } +}; +const expected = "1976-11-18T15:23:00"; + +assert.sameValue(dt.toString(), expected, "default is calendar = auto (zero arguments)"); +assert.sameValue(dt.toString({ calendarName: "auto" }), expected, "shows only non-ISO calendar if calendarName = auto"); + +assert.sameValue( + dt.withCalendar(fakeISO8601Cal).toString({ calendarName: "auto" }), + expected, + "Don't show ISO calendar even if calendarName = auto" +); + +const dt2 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, customCal); + +assert.sameValue( + dt2.toString({ calendarName: "auto" }), + "1976-11-18T15:23:00[u-ca=bogus]", + "Don't show calendar if calendarName = auto & PlainDateTime has non-ISO calendar" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string.js index 985ad225ac..e17d9d1e44 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string.js @@ -15,4 +15,11 @@ features: [Temporal] ---*/ const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -assert.throws(RangeError, () => datetime.toString({ calendarName: "other string" })); +const invalidCals = ["other string", "ALWAYS", "sometimes", "auto\0"]; + +invalidCals.forEach((cal) => { + assert.throws( + RangeError, + () => datetime.toString({ calendarName: cal }), + `invalid calendar (${cal})`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..a27cec98d2 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-never.js @@ -0,0 +1,26 @@ +// 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.prototype.tostring +description: Do not show calendar if calendar name option is "never" +features: [Temporal] +---*/ + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); +const cal = { + toString() { return "bogus"; } +}; +const expected = "1976-11-18T15:23:00"; + +assert.sameValue( + dt.toString({ calendarName: "never" }), + expected, + "Do not show calendar if calendarName = never" +); + +assert.sameValue( + dt.withCalendar(cal).toString({ calendarName: "never" }), + expected, + "Do not show calendar when calendarName = never, even if non-ISO calendar is used" +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js new file mode 100644 index 0000000000..727b24ce90 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-always.js @@ -0,0 +1,16 @@ +// 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.prototype.tostring +description: Show calendar when calendarName is "always" +features: [Temporal] +---*/ + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory"); + +assert.sameValue( + dt.toString({ calendarName: "always" }), + "1976-11-18T15:23:00[u-ca=gregory]", + "shows non-ISO calendar if calendarName = always" +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js new file mode 100644 index 0000000000..2f9586a83d --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js @@ -0,0 +1,14 @@ +// 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.prototype.tostring +description: Possibly display calendar when calendarName is "auto" +features: [Temporal] +---*/ + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, "gregory"); +const expected = "1976-11-18T15:23:00[u-ca=gregory]"; + +assert.sameValue(dt.toString(), expected, "shows non-ISO calendar by default (no arguments)"); +assert.sameValue(dt.toString({ calendarName: "auto" }), expected, "shows only non-ISO calendar if calendarName = auto"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js new file mode 100644 index 0000000000..1bd9018a21 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toString/calendarname-never.js @@ -0,0 +1,16 @@ +// 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.prototype.tostring +description: Do not show calendar (even non-ISO calendars) if calendarName = "never" +features: [Temporal] +---*/ + +const dt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +assert.sameValue( + dt.withCalendar("gregory").toString({ calendarName: "never" }), + "1976-11-18T15:23:00", + "omits non-ISO calendar if calendarName = never" +);