Skip to content

Commit

Permalink
Regularize "calendar-case-insensitive" tests
Browse files Browse the repository at this point in the history
For each entry point where a string calendar name is accepted, we should
have a test that ensures the calendar name is case-insensitive. These
tests existed but several were incomplete as they didn't take nested
properties into account, and several entry points were missing this test.

Fix a minor copy-paste issue with double semicolons.
  • Loading branch information
ptomato authored and Ms2ger committed Feb 1, 2023
1 parent 8700c92 commit 374aac4
Show file tree
Hide file tree
Showing 50 changed files with 414 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.calendar.prototype.dateuntil
description: The calendar name is case-insensitive
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (second argument)");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property, first argument)");
const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property, second argument)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.day(arg);
assert.sameValue(result, 18, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.day(arg);
assert.sameValue(result1, 18, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.day(arg);
assert.sameValue(result2, 18, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dayOfWeek(arg);
assert.sameValue(result, 4, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfWeek(arg);
assert.sameValue(result1, 4, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfWeek(arg);
assert.sameValue(result2, 4, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dayOfYear(arg);
assert.sameValue(result, 323, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dayOfYear(arg);
assert.sameValue(result1, 323, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dayOfYear(arg);
assert.sameValue(result2, 323, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInMonth(arg);
assert.sameValue(result, 30, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInMonth(arg);
assert.sameValue(result1, 30, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInMonth(arg);
assert.sameValue(result2, 30, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInWeek(arg);
assert.sameValue(result, 7, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInWeek(arg);
assert.sameValue(result1, 7, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInWeek(arg);
assert.sameValue(result2, 7, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInYear(arg);
assert.sameValue(result, 366, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.daysInYear(arg);
assert.sameValue(result1, 366, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.daysInYear(arg);
assert.sameValue(result2, 366, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.inLeapYear(arg);
assert.sameValue(result, true, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.inLeapYear(arg);
assert.sameValue(result1, true, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.inLeapYear(arg);
assert.sameValue(result2, true, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.month(arg);
assert.sameValue(result, 11, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.month(arg);
assert.sameValue(result1, 11, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.month(arg);
assert.sameValue(result2, 11, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.monthCode(arg);
assert.sameValue(result, "M11", `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.monthCode(arg);
assert.sameValue(result1, "M11", "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.monthCode(arg);
assert.sameValue(result2, "M11", "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.monthsInYear(arg);
assert.sameValue(result, 12, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.monthsInYear(arg);
assert.sameValue(result1, 12, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.monthsInYear(arg);
assert.sameValue(result2, 12, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.weekOfYear(arg);
assert.sameValue(result, 47, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.weekOfYear(arg);
assert.sameValue(result1, 47, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.weekOfYear(arg);
assert.sameValue(result2, 47, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.year(arg);
assert.sameValue(result, 1976, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.year(arg);
assert.sameValue(result1, 1976, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.year(arg);
assert.sameValue(result2, 1976, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.calendar.prototype.yearofweek
description: The calendar name is case-insensitive
features: [Temporal]
---*/

const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.yearOfWeek(arg);
assert.sameValue(result1, 1976, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.yearOfWeek(arg);
assert.sameValue(result2, 1976, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ features: [Temporal]

const instance = new Temporal.Instant(1_000_000_000_000_000_000n);

const arg = "iSo8601";;
const arg = "iSo8601";
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.compare
description: The calendar name is case-insensitive
features: [Temporal]
---*/

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18));
assert.sameValue(result1, 0, "Calendar is case-insensitive (first argument)");
const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg);
assert.sameValue(result2, 0, "Calendar is case-insensitive (second argument)");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18));
assert.sameValue(result3, 0, "Calendar is case-insensitive (nested property, first argument)");
const result4 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg);
assert.sameValue(result4, 0, "Calendar is case-insensitive (nested property, second argument)");
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ features: [Temporal]

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = Temporal.PlainDate.from(arg);
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = Temporal.PlainDate.from(arg);
TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = Temporal.PlainDate.from(arg);
TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.PlainDate(1976, 11, 18);

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.equals(arg);
assert.sameValue(result, true, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.equals(arg);
assert.sameValue(result1, true, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.equals(arg);
assert.sameValue(result2, true, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const instance = new Temporal.PlainDate(1976, 11, 18);

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.since(arg);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.since(arg);
TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.since(arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const instance = new Temporal.PlainDate(1976, 11, 18);

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.until(arg);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.until(arg);
TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.until(arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ features: [Temporal]

const instance = new Temporal.PlainDate(1976, 11, 18, { id: "replace-me" });

const arg = "iSo8601";;
const arg = "iSo8601";
const result = instance.withCalendar(arg);
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.compare
description: The calendar name is case-insensitive
features: [Temporal]
---*/

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18));
assert.sameValue(result1, 0, "Calendar is case-insensitive (first argument)");
const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg);
assert.sameValue(result2, 0, "Calendar is case-insensitive (second argument)");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18));
assert.sameValue(result3, 0, "Calendar is case-insensitive (nested property, first argument)");
const result4 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg);
assert.sameValue(result4, 0, "Calendar is case-insensitive (nested property, second argument)");
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ features: [Temporal]

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = Temporal.PlainDateTime.from(arg);
TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = Temporal.PlainDateTime.from(arg);
TemporalHelpers.assertPlainDateTime(result1, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = Temporal.PlainDateTime.from(arg);
TemporalHelpers.assertPlainDateTime(result2, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const instance = new Temporal.PlainDateTime(1976, 11, 18);

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.equals(arg);
assert.sameValue(result, true, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.equals(arg);
assert.sameValue(result1, true, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.equals(arg);
assert.sameValue(result2, true, "Calendar is case-insensitive (nested property)");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const instance = new Temporal.PlainDateTime(1976, 11, 18);

const calendar = "IsO8601";

const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.since(arg);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, `Calendar created from string "${calendar}"`);
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.since(arg);
TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.since(arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property)");
Loading

0 comments on commit 374aac4

Please sign in to comment.