Temporal: Extend tests for PlainDate#toString.

This commit is contained in:
Ms2ger 2022-06-13 11:54:22 +02:00 committed by Philip Chimento
parent 194f7426f9
commit 3812a1fe92
6 changed files with 57 additions and 25 deletions

View File

@ -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.plaindate.protoype.tostring
description: Should always call 'toString' on the calendar once.
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
++calls;
return "custom";
}
};
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]) => {
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'`);
});

View File

@ -7,15 +7,16 @@ description: always value for calendarName option
features: [Temporal]
---*/
const calendar = {
const customCalendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
const customISOCalendar = {
toString() { return "iso8601"; }
};
[
[date1, "2000-05-02[u-ca=iso8601]"],
[date2, "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02[u-ca=iso8601]"],
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02[u-ca=iso8601]"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "always" });
assert.sameValue(result, expected, "expected " + expected);

View File

@ -7,15 +7,16 @@ description: auto value for calendarName option
features: [Temporal]
---*/
const calendar = {
const customCalendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
const customISOCalendar = {
toString() { return "iso8601"; }
};
[
[date1, "2000-05-02"],
[date2, "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "auto" });
assert.sameValue(result, expected, "expected " + expected);

View File

@ -15,7 +15,7 @@ features: [Temporal]
---*/
const date = new Temporal.PlainDate(2000, 5, 2);
const values = ["ALWAYS", "sometimes", "other string"];
const values = ["ALWAYS", "sometimes", "other string", "auto\0"];
for (const calendarName of values) {
assert.throws(RangeError, () => date.toString({ calendarName }));

View File

@ -7,15 +7,16 @@ description: never value for calendarName option
features: [Temporal]
---*/
const calendar = {
const customCalendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
const customISOCalendar = {
toString() { return "iso8601"; }
};
[
[date1, "2000-05-02"],
[date2, "2000-05-02"],
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02"],
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "never" });
assert.sameValue(result, expected, "expected " + expected);

View File

@ -14,15 +14,16 @@ info: |
features: [Temporal]
---*/
const calendar = {
const customCalendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
const customISOCalendar = {
toString() { return "iso8601"; }
};
[
[date1, "2000-05-02"],
[date2, "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2), "2000-05-02"],
[new Temporal.PlainDate(2000, 5, 2, customCalendar), "2000-05-02[u-ca=custom]"],
[new Temporal.PlainDate(2000, 5, 2, customISOCalendar), "2000-05-02"],
].forEach(([date, expected]) => {
const explicit = date.toString({ calendarName: undefined });
assert.sameValue(explicit, expected, "default calendarName option is auto");