Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More follow-up on closed Temporal tests PRs #3456

Merged
merged 5 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.inleapyear
description: An ISO 8601 date string should be converted as input
info: |
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]).
features: [Temporal]
---*/

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

assert.sameValue(cal.inLeapYear("2019-03-18"), false);
assert.sameValue(cal.inLeapYear("2020-03-18"), true);

assert.sameValue(cal.inLeapYear("+002023-03-18"), false);
assert.sameValue(cal.inLeapYear("+002024-03-18"), true);

assert.sameValue(cal.inLeapYear("2019-03-18T13:00:00+00:00[UTC]"), false);
assert.sameValue(cal.inLeapYear("2020-12-31T23:59:59+00:00[UTC]"), true);

assert.sameValue(cal.inLeapYear("+002023-03-18T13:00:00+00:00[UTC]"), false);
assert.sameValue(cal.inLeapYear("+002024-03-18T13:00:00+00:00[UTC]"), true);
17 changes: 13 additions & 4 deletions test/built-ins/Temporal/Calendar/prototype/inLeapYear/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ features: [Temporal]
---*/

const iso = Temporal.Calendar.from("iso8601");
const res = false;
assert.sameValue(iso.inLeapYear(Temporal.PlainDate.from("1994-11-05")), res, "PlainDate");
assert.sameValue(iso.inLeapYear(Temporal.PlainDateTime.from("1994-11-05T08:15:30")), res, "PlainDateTime");
assert.sameValue(iso.inLeapYear(Temporal.PlainYearMonth.from("1994-11")), res, "PlainYearMonth");
let res = false;

assert.sameValue(iso.inLeapYear(new Temporal.PlainDate(1994, 11, 5)), res, "PlainDate");
assert.sameValue(iso.inLeapYear(new Temporal.PlainDateTime(1994, 11, 5, 8, 15, 30)), res, "PlainDateTime");
assert.sameValue(iso.inLeapYear(new Temporal.PlainYearMonth(1994, 11)), res, "PlainYearMonth");
assert.sameValue(iso.inLeapYear({ year: 1994, month: 11, day: 5 }), res, "property bag");
assert.sameValue(iso.inLeapYear("1994-11-05"), res, "string");

res = true;
assert.sameValue(iso.inLeapYear(new Temporal.PlainDate(1996, 7, 15)), res, "PlainDate in leap year");
assert.sameValue(iso.inLeapYear(new Temporal.PlainDateTime(1996, 7, 15, 5, 30, 13)), res, "PlainDateTime in leap year");
assert.sameValue(iso.inLeapYear(new Temporal.PlainYearMonth(1996, 7)), res, "PlainYearMonth in leap year");
assert.sameValue(iso.inLeapYear({ year: 1996, month: 7, day: 15 }), res, "property bag in leap year");
assert.sameValue(iso.inLeapYear("1996-07-15"), res, "string in leap year");

assert.throws(TypeError, () => iso.inLeapYear({ year: 2000 }), "property bag with missing properties");
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const inLeapYear = Temporal.Calendar.prototype.inLeapYear;

assert.sameValue(typeof inLeapYear, "function");

assert.throws(TypeError, () => inLeapYear.call(undefined), "undefined");
assert.throws(TypeError, () => inLeapYear.call(null), "null");
assert.throws(TypeError, () => inLeapYear.call(true), "true");
assert.throws(TypeError, () => inLeapYear.call(""), "empty string");
assert.throws(TypeError, () => inLeapYear.call(Symbol()), "symbol");
assert.throws(TypeError, () => inLeapYear.call(1), "1");
assert.throws(TypeError, () => inLeapYear.call({}), "plain object");
assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar), "Temporal.Calendar");
assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar.prototype), "Temporal.Calendar.prototype");
const arg = new Temporal.PlainDate(2021, 3, 4);

assert.throws(TypeError, () => inLeapYear.call(undefined, arg), "undefined");
assert.throws(TypeError, () => inLeapYear.call(null, arg), "null");
assert.throws(TypeError, () => inLeapYear.call(true, arg), "true");
assert.throws(TypeError, () => inLeapYear.call("", arg), "empty string");
assert.throws(TypeError, () => inLeapYear.call(Symbol(), arg), "symbol");
assert.throws(TypeError, () => inLeapYear.call(1, arg), "1");
assert.throws(TypeError, () => inLeapYear.call({}, arg), "plain object");
assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar, arg), "Temporal.Calendar");
assert.throws(TypeError, () => inLeapYear.call(Temporal.Calendar.prototype, arg), "Temporal.Calendar.prototype");
33 changes: 33 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/mergeFields/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// 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.mergefields
description: >
Temporal.Calendar.prototype.mergeFields will merge own data properties on its
arguments
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Set fields to ? ToObject(fields).
5. Set additionalFields to ? ToObject(additionalFields).
6. Return ? DefaultMergeFields(fields, additionalFields).
features: [Temporal]
includes: [deepEqual.js]
---*/

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

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2 }, { c: 3, d: 4 }),
{ a: 1, b: 2, c: 3, d: 4 },
"properties are merged"
);

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2 }, { b: 3, c: 4 }),
{ a: 1, b: 3, c: 4 },
"property in additionalFields should overwrite one in fields"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.mergefields
description: >
The default mergeFields algorithm from the ISO 8601 calendar should correctly
merge the month and monthCode properties
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Set fields to ? ToObject(fields).
5. Set additionalFields to ? ToObject(additionalFields).
6. Return ? DefaultMergeFields(fields, additionalFields).
features: [Temporal]
includes: [deepEqual.js]
---*/

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

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7 }, { b: 3, c: 4 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

image

{ a: 1, b: 3, c: 4, month: 7 },
"month is copied from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, monthCode: "M08" }, { b: 3, c: 4 }),
{ a: 1, b: 3, c: 4, monthCode: "M08" },
"monthCode is copied from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7, monthCode: "M08" }, { b: 3, c: 4 }),
{ a: 1, b: 3, c: 4, month: 7, monthCode: "M08" },
"both month and monthCode are copied from fields, no validation is performed"
);

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2 }, { b: 3, c: 4, month: 5 }),
{ a: 1, b: 3, c: 4, month: 5 },
"month is copied from additionalFields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2 }, { b: 3, c: 4, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, monthCode: "M06" },
"monthCode is copied from additionalFields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2 }, { b: 3, c: 4, month: 5, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, month: 5, monthCode: "M06" },
"both month and monthCode are copied from additionalFields, no validation is performed"
);

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7 }, { b: 3, c: 4, month: 5 }),
{ a: 1, b: 3, c: 4, month: 5 },
"month from additionalFields overrides month from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, monthCode: "M07" }, { b: 3, c: 4, monthCode: "M05" }),
{ a: 1, b: 3, c: 4, monthCode: "M05" },
"monthCode from additionalFields overrides monthCode from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, monthCode: "M07" }, { b: 3, c: 4, month: 6 }),
{ a: 1, b: 3, c: 4, month: 6 },
"month's presence on additionalFields blocks monthCode from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7 }, { b: 3, c: 4, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, monthCode: "M06"},
"monthCode's presence on additionalFields blocks month from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7, monthCode: "M08" },{ b: 3, c: 4, month: 5 }),
{ a: 1, b: 3, c: 4, month: 5 },
"month's presence on additionalFields blocks both month and monthCode from fields"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7, monthCode: "M08" }, { b: 3, c: 4, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, monthCode: "M06" },
"monthCode's presence on additionalFields blocks both month and monthCode from fields"
);

assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7 }, { b: 3, c: 4, month: 5, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, month: 5, monthCode: "M06" },
"both month and monthCode are copied from additionalFields even when fields has month"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, monthCode: "M07" }, { b: 3, c: 4, month: 5, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, month: 5, monthCode: "M06" },
"both month and monthCode are copied from additionalFields even when fields has monthCode"
);
assert.deepEqual(
cal.mergeFields({ a: 1, b: 2, month: 7, monthCode: "M08" }, { b: 3, c: 4, month: 5, monthCode: "M06" }),
{ a: 1, b: 3, c: 4, month: 5, monthCode: "M06" },
"both month and monthCode are copied from additionalFields even when fields has both month and monthCode"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// 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.mergefields
description: Only string keys from the arguments are merged
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Set fields to ? ToObject(fields).
5. Set additionalFields to ? ToObject(additionalFields).
6. Return ? DefaultMergeFields(fields, additionalFields).
features: [Temporal]
includes: [deepEqual.js]
---*/

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

assert.deepEqual(
cal.mergeFields({ 1: 2 }, { 3: 4 }),
{ "1": 2, "3": 4 },
"number keys are actually string keys and are merged as such"
);
assert.deepEqual(
cal.mergeFields({ 1n: 2 }, { 2n: 4 }),
{ "1": 2, "2": 4 },
"bigint keys are actually string keys and are merged as such"
);

const foo = Symbol("foo");
const bar = Symbol("bar");
assert.deepEqual(cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }), {}, "symbol keys are not merged");
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.monthdayfromfields
description: Temporal.Calendar.prototype.monthDayFromFields will return correctly with valid data.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
includes: [temporalHelpers.js]
features: [Temporal]
---*/

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

let result = cal.monthDayFromFields({ year: 2021, month: 7, day: 3 });
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "month 7, day 3, with year");
result = cal.monthDayFromFields({ year: 2021, month: 12, day: 31 });
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 12, day 31, with year");
result = cal.monthDayFromFields({ monthCode: "M07", day: 3 });
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "monthCode M07, day 3");
result = cal.monthDayFromFields({ monthCode: "M12", day: 31 });
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "monthCode M12, day 31");

["constrain", "reject"].forEach(function (overflow) {
const opt = { overflow };
result = cal.monthDayFromFields({ year: 2021, month: 7, day: 3 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "month 7, day 3, with year");
result = cal.monthDayFromFields({ year: 2021, month: 12, day: 31 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "month 12, day 31, with year");
result = cal.monthDayFromFields({ monthCode: "M07", day: 3 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M07", 3, "monthCode M07, day 3");
result = cal.monthDayFromFields({ monthCode: "M12", day: 31 }, opt);
TemporalHelpers.assertPlainMonthDay(result, "M12", 31, "monthCode M12, day 31");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.monthdayfromfields
description: Temporal.Calendar.prototype.monthDayFromFields will throw TypeError with incorrect input data type.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
features: [Temporal]
---*/

let cal = new Temporal.Calendar("iso8601")

assert.throws(TypeError, () => cal.monthDayFromFields({}), "at least one correctly spelled property is required");
assert.throws(TypeError, () => cal.monthDayFromFields({ monthCode: "M12" }), "day is required with monthCode");
assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, month: 12 }), "day is required with year and month");
assert.throws(TypeError, () => cal.monthDayFromFields({ month: 1, day: 17 }), "year is required if month is present");
assert.throws(TypeError, () => cal.monthDayFromFields({ year: 2021, day: 17 }), "either month or monthCode is required");
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Throw a TypeError if the fields is not an object
features: [Symbol, Temporal]
---*/

const tests = [undefined, null, false, "string", Symbol("sym"), Math.PI, 42n];
const tests = [undefined, null, true, false, "string", Symbol("sym"), Math.PI, Infinity, NaN, 42n];
const iso = Temporal.Calendar.from("iso8601");
for (const fields of tests) {
assert.throws(TypeError, () => iso.monthDayFromFields(fields, {}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.calendar.prototype.monthdayfromfields
description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISOMonthDayFromFields(fields, options).
7. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], calendar, result.[[ReferenceISOYear]]).
features: [Temporal]
---*/

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

["m1", "M1", "m01"].forEach((monthCode) => {
assert.throws(RangeError, () => cal.monthDayFromFields({ monthCode, day: 17 }),
`monthCode '${monthCode}' is not well-formed`);
});

assert.throws(RangeError, () => cal.monthDayFromFields({ year: 2021, month: 12, monthCode: "M11", day: 17 }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13"].forEach((monthCode) => {
assert.throws(RangeError, () => cal.monthDayFromFields({ monthCode, day: 17 }),
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
});
Loading