Skip to content

Commit

Permalink
Move testing of era/eraYear under intl402 (#3517)
Browse files Browse the repository at this point in the history
* Move testing of era/eraYear under intl402

* remove era/eraYear from built-in tests.
  • Loading branch information
FrankYFTang authored May 3, 2022
1 parent 28455b1 commit 06fafd7
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ includes: [temporalHelpers.js]

const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
Expand All @@ -26,9 +24,8 @@ const shifted = pdt.withPlainDate(pd);
TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is changed if receiver has ISO calendar (1)",
"the era",
1909
"calendar is changed if receiver has ISO calendar (1)"
// Testing of era and eraYear should only be coded under intl402
);

assert.sameValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const cal1 = {
};
const cal2 = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
Expand All @@ -28,9 +26,8 @@ const shifted = pdt.withPlainDate(pd);
TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is changed with same id (1)",
"the era",
1909
"calendar is changed with same id (1)"
// Testing of era and eraYear should only be coded under intl402
);

assert.sameValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ includes: [temporalHelpers.js]
let calls = 0;
const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() {
++calls;
return "this is a string";
Expand All @@ -29,9 +27,8 @@ const shifted = pdt.withPlainDate(pd);
TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged with same calendars (1)",
"the era",
1909
"calendar is unchanged with same calendars (1)"
// Testing of era and eraYear should only be coded under intl402
);

assert.sameValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ includes: [temporalHelpers.js]

const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
Expand All @@ -26,9 +24,8 @@ const shifted = pdt.withPlainDate(pd);
TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged if input has ISO calendar (1)",
"the era",
1909
"calendar is unchanged if input has ISO calendar (1)"
// Testing of era and eraYear should only be coded under intl402
);

assert.sameValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ includes: [temporalHelpers.js]

const cal = {
id: "thisisnotiso",
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
Expand All @@ -24,9 +22,8 @@ const shifted = dt.withPlainDate("2010-11-12");
TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged if input has ISO calendar (1)",
"the era",
1909
"calendar is unchanged if input has ISO calendar (1)"
// Testing of era and eraYear should only be coded under intl402
);

assert.sameValue(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.withplaindate
description: PlainDate calendar is preserved with ISO PDT
features: [Temporal]
includes: [temporalHelpers.js]
---*/

const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },
day() { return 6; }
};
const pdt = new Temporal.PlainDateTime(1995, 12, 7, 3, 24, 30, 0, 0, 0);
assert.sameValue(pdt.calendar.toString(), "iso8601", "PlainDateTime with ISO calendar");
const pd = new Temporal.PlainDate(2010, 11, 12, cal);
const shifted = pdt.withPlainDate(pd);

TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is changed if receiver has ISO calendar (1)",
"the era",
1909
);

assert.sameValue(
shifted.calendar,
cal,
"calendar is changed if receiver has ISO calendar (2)"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.withplaindate
description: PlainDate calendar is preserved when both calendars have the same id
features: [Temporal]
includes: [temporalHelpers.js]
---*/

const cal1 = {
toString() { return "this is a string"; },
};
const cal2 = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },
day() { return 6; }
};
const pdt = new Temporal.PlainDateTime(1995, 12, 7, 3, 24, 30, 0, 0, 0, cal1);
const pd = new Temporal.PlainDate(2010, 11, 12, cal2);
const shifted = pdt.withPlainDate(pd);

TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is changed with same id (1)",
"the era",
1909
);

assert.sameValue(
shifted.calendar,
cal2,
"calendar is changed with same id (2)"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.withplaindate
description: PlainDate calendar is preserved when both calendars are the same object
features: [Temporal]
includes: [temporalHelpers.js]
---*/

let calls = 0;
const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() {
++calls;
return "this is a string";
},
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },
day() { return 6; }
};
const pdt = new Temporal.PlainDateTime(1995, 12, 7, 3, 24, 30, 0, 0, 0, cal);
const pd = new Temporal.PlainDate(2010, 11, 12, cal);
const shifted = pdt.withPlainDate(pd);

TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged with same calendars (1)",
"the era",
1909
);

assert.sameValue(
shifted.calendar,
cal,
"calendar is unchanged with same calendars (2)"
);
assert.sameValue(calls, 0, "should not have called cal.toString()");
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.withplaindate
description: Original PDT calendar is preserved with ISO PlainDate
features: [Temporal]
includes: [temporalHelpers.js]
---*/

const cal = {
id: 'thisisnotiso',
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },
day() { return 6; }
};
const pdt = new Temporal.PlainDateTime(1995, 12, 7, 3, 24, 30, 0, 0, 0, cal);
const pd = new Temporal.PlainDate(2010, 11, 12);
assert.sameValue(pd.calendar.toString(), "iso8601", "PlainDate with ISO calendar");
const shifted = pdt.withPlainDate(pd);

TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged if input has ISO calendar (1)",
"the era",
1909
);

assert.sameValue(
shifted.calendar,
cal,
"calendar is unchanged if input has ISO calendar (2)"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.withplaindate
description: Original PDT calendar is preserved with ISO string
features: [Temporal]
includes: [temporalHelpers.js]
---*/

const cal = {
id: "thisisnotiso",
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },
day() { return 6; }
};
const dt = new Temporal.PlainDateTime(1995, 12, 7, 3, 24, 30, 0, 0, 0, cal);
const shifted = dt.withPlainDate("2010-11-12");

TemporalHelpers.assertPlainDateTime(
shifted,
2008, 9, "M09", 6, 3, 24, 30, 0, 0, 0,
"calendar is unchanged if input has ISO calendar (1)",
"the era",
1909
);

assert.sameValue(
shifted.calendar,
cal,
"calendar is unchanged if input has ISO calendar (2)"
);

0 comments on commit 06fafd7

Please sign in to comment.