Skip to content

Commit

Permalink
Temporal: Add tests for calendarName: "critical" option
Browse files Browse the repository at this point in the history
See tc39/proposal-temporal#2397
This normative change adds a new accepted value for the calendarName
option in various toString() methods.
  • Loading branch information
ptomato authored and Ms2ger committed Oct 11, 2022
1 parent 0c18f70 commit c0bb28d
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit c0bb28d

Please sign in to comment.