Add tests for PlainDate#toString().

This commit is contained in:
Ms2ger 2021-12-23 12:27:40 +01:00 committed by Rick Waldron
parent 08a9fc2b97
commit 0855621088
4 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// Copyright (C) 2021 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: basic tests
features: [Temporal]
---*/
const date1 = new Temporal.PlainDate(1976, 11, 18);
assert.sameValue(date1.toString(), "1976-11-18");
const date2 = new Temporal.PlainDate(1914, 2, 23);
assert.sameValue(date2.toString(), "1914-02-23");
const date3 = new Temporal.PlainDate(1996, 2, 29);
assert.sameValue(date3.toString(), "1996-02-29");

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 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: always value for calendarName option
features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
[
[date1, "2000-05-02[u-ca=iso8601]"],
[date2, "2000-05-02[u-ca=custom]"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "always" });
assert.sameValue(result, expected, "expected " + expected);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 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: auto value for calendarName option
features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
[
[date1, "2000-05-02"],
[date2, "2000-05-02[u-ca=custom]"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "auto" });
assert.sameValue(result, expected, "expected " + expected);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 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: never value for calendarName option
features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);
[
[date1, "2000-05-02"],
[date2, "2000-05-02"],
].forEach(([date, expected]) => {
const result = date.toString({ calendarName: "never" });
assert.sameValue(result, expected, "expected " + expected);
});