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

Add tests for Temporal.Calendar.p*.mergeFields #3057

Closed
wants to merge 1 commit into from
Closed
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.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})));
Copy link
Contributor

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 of compareArray?

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})));
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
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})));