1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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"
);
reportCompare(0, 0);
|