-
Notifications
You must be signed in to change notification settings - Fork 461
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
Add tests for Temporal.Calendar.p*.mergeFields #3057
Closed
Closed
Changes from all commits
Commits
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/mergeFields/simple.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.mergefields | ||
description: Temporal.Calendar.prototype.mergeFields will merge data. | ||
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: [compareArray.js] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601") | ||
|
||
// Assert only string will be merged | ||
assert(compareArray({}, cal.mergeFields({1: 2}, {3: 4}))); | ||
assert(compareArray({}, cal.mergeFields({true: 2}, {false: 4}))); | ||
assert(compareArray({}, cal.mergeFields({1n: 2}, {2n: 4}))); | ||
assert(compareArray({}, cal.mergeFields({Infinity: 2}, {Infinity: 4}))); | ||
assert(compareArray({}, cal.mergeFields({undefined: 2}, {NaN: 4}))); | ||
assert(compareArray({}, cal.mergeFields({["foo"]: 2}, {["bar"]: 4}))); | ||
assert(compareArray({a:1, b:2, c:4}, cal.mergeFields({a: 1, b: 2}, {b:3, c:4}))); |
31 changes: 31 additions & 0 deletions
31
test/built-ins/Temporal/Calendar/prototype/mergeFields/throws-type-error.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.mergefields | ||
description: Temporal.Calendar.prototype.mergeFields will throw TypeError with incorrect input. | ||
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] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601") | ||
|
||
// Test throwing | ||
assert.throws(TypeError, () => cal.mergeFields(), | ||
"Cannot convert undefined or null to object"); | ||
assert.throws(TypeError, () => cal.mergeFields(undefined, {}), | ||
"Cannot convert undefined or null to object"); | ||
assert.throws(TypeError, () => cal.mergeFields(null, {}), | ||
"Cannot convert undefined or null to object"); | ||
assert.throws(TypeError, () => cal.mergeFields({}, undefined), | ||
"Cannot convert undefined or null to object"); | ||
assert.throws(TypeError, () => cal.mergeFields({}, null), | ||
"Cannot convert undefined or null to object"); | ||
|
||
// Test String, number, true, false, NaN, BigInt, Symbol types | ||
// pending on https://github.com/tc39/proposal-temporal/issues/1647 |
50 changes: 50 additions & 0 deletions
50
test/built-ins/Temporal/Calendar/prototype/mergeFields/with-month.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,50 @@ | ||
// 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: Temporal.Calendar.prototype.mergeFields will merge data while there are month or monthCode in the data. | ||
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: [compareArray.js] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601") | ||
|
||
assert(compareArray({a:1, b:2, c:4, month:5}, | ||
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5}))); | ||
assert(compareArray({a:1, b:2, c:4, month:5, month:'M06'}, | ||
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5, monthCode:'M06'}))); | ||
assert(compareArray({a:1, b:2, c:4, month:'M06'}, cal.mergeFields({a: 1, b: 2}, | ||
{b:3, c:4, monthCode:'M06'}))); | ||
|
||
assert(compareArray({a:1, b:2, c:4, month:5}, | ||
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, month:5}))); | ||
assert(compareArray({a:1, b:2, c:4, month:5}, | ||
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, | ||
{b:3, c:4, month:5}))); | ||
assert(compareArray({a:1, b:2, c:4, monthCode:'M06'}, | ||
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, monthCode:'M06'}))); | ||
assert(compareArray({a:1, b:2, c:4, monthCode:'M06'}, | ||
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, | ||
{b:3, c:4, monthCode:'M06'}))); | ||
assert(compareArray({a:1, b:2, c:4, month:5, monthCode:'M06'}, | ||
cal.mergeFields({a: 1, b: 2, month:7}, | ||
{b:3, c:4, month:5, monthCode:'M06'}))); | ||
assert(compareArray({a:1, b:2, c:4, month:5, monthCode:'M06'}, | ||
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, | ||
{b:3, c:4, month:5, monthCode:'M06'}))); | ||
|
||
assert(compareArray({a:1, b:2, c:4, month:7}, | ||
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4}))); | ||
assert(compareArray({a:1, b:2, c:4, month:5, monthCode:'M08'}, | ||
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}))); | ||
assert(compareArray({a:1, b:2, c:4, month:7, monthCode:'M08'}, | ||
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}))); | ||
assert(compareArray({a:1, b:2, c:4, monthCode:'M08'}, | ||
cal.mergeFields({a: 1, b: 2, monthCode:'M08'}, {b:3, c:4}))); |
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.
Doesn't this need
deepEqual
instead ofcompareArray
?