mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for Temporal.Calendar.p*.mergeFields
(Philip, March 2022: This was originally Frank's PR #3057. I did some reformatting, removed duplicate tests, addressed the review comments that I left the first time around, and added some cases that I felt were not yet complete.)
This commit is contained in:
parent
6bae30c1b2
commit
16aefcc6cf
33
test/built-ins/Temporal/Calendar/prototype/mergeFields/basic.js
vendored
Normal file
33
test/built-ins/Temporal/Calendar/prototype/mergeFields/basic.js
vendored
Normal file
@ -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
test/built-ins/Temporal/Calendar/prototype/mergeFields/iso8601-calendar-month-monthCode.js
vendored
Normal file
99
test/built-ins/Temporal/Calendar/prototype/mergeFields/iso8601-calendar-month-monthCode.js
vendored
Normal file
@ -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
test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js
vendored
Normal file
34
test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js
vendored
Normal file
@ -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");
|
Loading…
x
Reference in New Issue
Block a user