Skip to content

Commit

Permalink
Temporal: Port Demitasse tests for PlainDateTime's toString
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama authored and Ms2ger committed Apr 28, 2022
1 parent 28b31c0 commit dcd25e6
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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"
);
Original file line number Diff line number Diff line change
@@ -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"
);
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
});
Original file line number Diff line number Diff line change
@@ -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"
);
Original file line number Diff line number Diff line change
@@ -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"
);
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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"
);

0 comments on commit dcd25e6

Please sign in to comment.