From c0bb28d2f34e2bcc2dc2b5bdbb6bbefd995bda7e Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 7 Oct 2022 18:11:35 -0700 Subject: [PATCH] Temporal: Add tests for calendarName: "critical" option See https://github.com/tc39/proposal-temporal/pull/2397 This normative change adds a new accepted value for the calendarName option in various toString() methods. --- .../prototype/toString/calendar-tostring.js | 1 + .../toString/calendarname-critical.js | 24 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 2 +- .../toString/calendarname-undefined.js | 2 +- .../toString/calendarname-wrong-type.js | 2 +- .../prototype/toString/calendar-tostring.js | 1 + .../toString/calendarname-critical.js | 24 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 2 +- .../toString/calendarname-undefined.js | 2 +- .../toString/calendarname-wrong-type.js | 2 +- .../prototype/toString/calendar-tostring.js | 1 + .../toString/calendarname-critical.js | 24 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 2 +- .../toString/calendarname-undefined.js | 2 +- .../toString/calendarname-wrong-type.js | 2 +- .../prototype/toString/calendar-tostring.js | 1 + .../toString/calendarname-critical.js | 24 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 2 +- .../toString/calendarname-undefined.js | 2 +- .../toString/calendarname-wrong-type.js | 2 +- .../prototype/toString/calendar-tostring.js | 1 + .../toString/calendarname-critical.js | 24 +++++++++++++++++++ .../toString/calendarname-invalid-string.js | 2 +- .../toString/calendarname-undefined.js | 2 +- .../toString/calendarname-wrong-type.js | 2 +- 25 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.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 38f5573938d..7dd8ee3a49b 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendar-tostring.js @@ -18,6 +18,7 @@ const date = new Temporal.PlainDate(2000, 5, 2, customCalendar); [ ["always", "2000-05-02[u-ca=custom]", 1], ["auto", "2000-05-02[u-ca=custom]", 1], + ["critical", "2000-05-02[!u-ca=custom]", 1], ["never", "2000-05-02", 0], [undefined, "2000-05-02[u-ca=custom]", 1], ].forEach(([calendarName, expectedResult, expectedCalls]) => { diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js new file mode 100644 index 00000000000..1a2dee05303 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-critical.js @@ -0,0 +1,24 @@ +// 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.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-02[!u-ca=iso8601]", "built-in ISO"], + [[{ toString() { return "custom"; } }], "2000-05-02[!u-ca=custom]", "custom"], + [[{ toString() { return "iso8601"; } }], "2000-05-02[!u-ca=iso8601]", "custom with iso8601 toString"], + [[{ toString() { return "ISO8601"; } }], "2000-05-02[!u-ca=ISO8601]", "custom with caps toString"], + [[{ toString() { return "\u0131so8601"; } }], "2000-05-02[!u-ca=\u0131so8601]", "custom with dotless i toString"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDate(2000, 5, 2, ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} 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 fc476e02876..0d5900f944f 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 @@ -8,7 +8,7 @@ info: | sec-getoption step 10: 10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindate.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] 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 fafbd11fd88..b6b0c4f6852 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-undefined.js @@ -8,7 +8,7 @@ info: | sec-getoption step 3: 3. If _value_ is *undefined*, return _fallback_. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindate.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js index 2a621ea31f5..c14aa25a9c5 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toString/calendarname-wrong-type.js @@ -8,7 +8,7 @@ info: | sec-getoption step 9.a: a. Set _value_ to ? ToString(_value_). sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindate.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). includes: [compareArray.js, temporalHelpers.js] diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js index 0dc825c8fac..14538ab4cb1 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendar-tostring.js @@ -18,6 +18,7 @@ const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, c [ ["always", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], ["auto", "2000-05-02T12:34:56.987654321[u-ca=custom]", 1], + ["critical", "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]) => { diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js new file mode 100644 index 00000000000..69bbe1add4c --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-critical.js @@ -0,0 +1,24 @@ +// 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: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1976-11-18T15:23:00[!u-ca=iso8601]", "built-in ISO"], + [[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[!u-ca=custom]", "custom"], + [[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00[!u-ca=iso8601]", "custom with iso8601 toString"], + [[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[!u-ca=ISO8601]", "custom with caps toString"], + [[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[!u-ca=\u0131so8601]", "custom with dotless i toString"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 0, 0, 0, 0, ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} 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 6b880f0d3da..71c6cc8d530 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 @@ -8,7 +8,7 @@ info: | sec-getoption step 10: 10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js index 982732000e7..800fac39da5 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-undefined.js @@ -8,7 +8,7 @@ info: | sec-getoption step 3: 3. If _value_ is *undefined*, return _fallback_. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js index 171546b2120..a452be5bdba 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-wrong-type.js @@ -8,7 +8,7 @@ info: | sec-getoption step 9.a: a. Set _value_ to ? ToString(_value_). sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plaindatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). includes: [compareArray.js, temporalHelpers.js] diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendar-tostring.js index 6dc5cdea00a..1df2ef8da2e 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendar-tostring.js @@ -18,6 +18,7 @@ const monthday = new Temporal.PlainMonthDay(5, 2, customCalendar); [ ["always", "1972-05-02[u-ca=custom]", 1], ["auto", "1972-05-02[u-ca=custom]", 1], + ["critical", "1972-05-02[!u-ca=custom]", 1], ["never", "1972-05-02", 1], [undefined, "1972-05-02[u-ca=custom]", 1], ].forEach(([calendarName, expectedResult, expectedCalls]) => { diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js new file mode 100644 index 00000000000..f49b6f89ffb --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-critical.js @@ -0,0 +1,24 @@ +// 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.plainmonthday.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1972-05-02[!u-ca=iso8601]", "built-in ISO"], + [[{ toString() { return "custom"; } }], "1972-05-02[!u-ca=custom]", "custom"], + [[{ toString() { return "iso8601"; } }], "1972-05-02[!u-ca=iso8601]", "custom with iso8601 toString"], + [[{ toString() { return "ISO8601"; } }], "1972-05-02[!u-ca=ISO8601]", "custom with caps toString"], + [[{ toString() { return "\u0131so8601"; } }], "1972-05-02[!u-ca=\u0131so8601]", "custom with dotless i toString"], +]; + +for (const [args, expected, description] of tests) { + const monthday = new Temporal.PlainMonthDay(5, 2, ...args); + const result = monthday.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-invalid-string.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-invalid-string.js index 8ba02abe6b3..363c077a81a 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-invalid-string.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-invalid-string.js @@ -8,7 +8,7 @@ info: | sec-getoption step 10: 10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainmonthday.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js index 0b5bfaa756d..8fc2cde338d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-undefined.js @@ -8,7 +8,7 @@ info: | sec-getoption step 3: 3. If _value_ is *undefined*, return _fallback_. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainmonthday.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js index 260c7d3c877..39328d7e574 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toString/calendarname-wrong-type.js @@ -8,7 +8,7 @@ info: | sec-getoption step 9.a: a. Set _value_ to ? ToString(_value_). sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainmonthday.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). includes: [compareArray.js, temporalHelpers.js] diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendar-tostring.js index 86fda8251fd..3eec13d7791 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendar-tostring.js @@ -18,6 +18,7 @@ const yearmonth = new Temporal.PlainYearMonth(2000, 5, customCalendar); [ ["always", "2000-05-01[u-ca=custom]", 1], ["auto", "2000-05-01[u-ca=custom]", 1], + ["critical", "2000-05-01[!u-ca=custom]", 1], ["never", "2000-05-01", 1], [undefined, "2000-05-01[u-ca=custom]", 1], ].forEach(([calendarName, expectedResult, expectedCalls]) => { diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js new file mode 100644 index 00000000000..85e50d262c6 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-critical.js @@ -0,0 +1,24 @@ +// 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.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "2000-05-01[!u-ca=iso8601]", "built-in ISO"], + [[{ toString() { return "custom"; } }], "2000-05-01[!u-ca=custom]", "custom"], + [[{ toString() { return "iso8601"; } }], "2000-05-01[!u-ca=iso8601]", "custom with iso8601 toString"], + [[{ toString() { return "ISO8601"; } }], "2000-05-01[!u-ca=ISO8601]", "custom with caps toString"], + [[{ toString() { return "\u0131so8601"; } }], "2000-05-01[!u-ca=\u0131so8601]", "custom with dotless i toString"], +]; + +for (const [args, expected, description] of tests) { + const yearmonth = new Temporal.PlainYearMonth(2000, 5, ...args); + const result = yearmonth.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} 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 08e2abb86a1..8de67c2b1f6 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 @@ -8,7 +8,7 @@ info: | sec-getoption step 10: 10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainyearmonth.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js index 72e6a04cb58..23592c7d548 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-undefined.js @@ -8,7 +8,7 @@ info: | sec-getoption step 3: 3. If _value_ is *undefined*, return _fallback_. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainyearmonth.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js index 301b62703a9..4ad85fe1df5 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toString/calendarname-wrong-type.js @@ -8,7 +8,7 @@ info: | sec-getoption step 9.a: a. Set _value_ to ? ToString(_value_). sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.plainyearmonth.protoype.tostring step 4: 4. Let _showCalendar_ be ? ToShowCalendarOption(_options_). includes: [compareArray.js, temporalHelpers.js] diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js index 67476c0ebda..8d88548e442 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendar-tostring.js @@ -18,6 +18,7 @@ const date = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", custo [ ["always", "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", 1], ["auto", "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", 1], + ["critical", "2001-09-09T01:46:40.987654321+00:00[UTC][!u-ca=custom]", 1], ["never", "2001-09-09T01:46:40.987654321+00:00[UTC]", 0], [undefined, "2001-09-09T01:46:40.987654321+00:00[UTC][u-ca=custom]", 1], ].forEach(([calendarName, expectedResult, expectedCalls]) => { diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js new file mode 100644 index 00000000000..cd1742d82df --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-critical.js @@ -0,0 +1,24 @@ +// 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.prototype.tostring +description: > + If calendarName is "calendar", the calendar ID should be included and prefixed + with "!". +features: [Temporal] +---*/ + +const tests = [ + [[], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "built-in ISO"], + [[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=custom]", "custom"], + [[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "custom with iso8601 toString"], + [[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=ISO8601]", "custom with caps toString"], + [[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=\u0131so8601]", "custom with dotless i toString"], +]; + +for (const [args, expected, description] of tests) { + const date = new Temporal.ZonedDateTime(3661_987_654_321n, "UTC", ...args); + const result = date.toString({ calendarName: "critical" }); + assert.sameValue(result, expected, `${description} calendar for calendarName = critical`); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string.js index 51a7360c8db..38b6e158cac 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string.js @@ -8,7 +8,7 @@ info: | sec-getoption step 10: 10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.zoneddatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js index 509b56fcbde..3464bc79c21 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined.js @@ -8,7 +8,7 @@ info: | sec-getoption step 3: 3. If _value_ is *undefined*, return _fallback_. sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.zoneddatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). features: [Temporal] diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js index 5f1e7e73a9a..14e15ecd2a6 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type.js @@ -8,7 +8,7 @@ info: | sec-getoption step 9.a: a. Set _value_ to ? ToString(_value_). sec-temporal-toshowcalendaroption step 1: - 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « String », « *"auto"*, *"always"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, « *"string"* », « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*). sec-temporal.zoneddatetime.protoype.tostring step 6: 6. Let _showCalendar_ be ? ToShowCalendarOption(_options_). includes: [compareArray.js, temporalHelpers.js]