-
Notifications
You must be signed in to change notification settings - Fork 472
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6145fa
Add tests for Temporal.Calendar.p*.weekOfYear
FrankYFTang d267660
Add tests for Temporal.Calendar.p*.monthsInYear
FrankYFTang b637c20
Add tests for Temporal.Calendar.p*.monthDayFromFields
FrankYFTang 5e59ab0
Add tests for Temporal.Calendar.p*.mergeFields
FrankYFTang 2545c2e
Add tests for Temporal.Calendar.p*.inLeapYear
FrankYFTang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/built-ins/Temporal/Calendar/prototype/mergeFields/basic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); |
99 changes: 99 additions & 0 deletions
99
test/built-ins/Temporal/Calendar/prototype/mergeFields/iso8601-calendar-month-monthCode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
{ 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" | ||
); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
40 changes: 40 additions & 0 deletions
40
test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/basic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/fields-missing-properties.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/monthcode-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol