v8/test/mjsunit/temporal/calendar-merge-fields.js
Frank Tang f811e89269 [Temporal] Part2 Add constructor and simple getters.
Bug: v8:11544

Change-Id: I3206ca3e0c505b14e4497ccb2af25a31940a1c1e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967755
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78518}
2022-01-07 19:18:33 +00:00

59 lines
2.9 KiB
JavaScript

// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.mergefields
let cal = new Temporal.Calendar("iso8601")
// Test throwing
assertThrows(() => cal.mergeFields(), TypeError);
assertThrows(() => cal.mergeFields(undefined, {}), TypeError);
assertThrows(() => cal.mergeFields(null, {}), TypeError);
assertThrows(() => cal.mergeFields({}, undefined), TypeError);
assertThrows(() => cal.mergeFields({}, null), TypeError);
// Test String, number, true, false, NaN, BigInt, Symbol types
// pending on https://github.com/tc39/proposal-temporal/issues/1647
// Assert only string will be merged
assertArrayEquals({}, cal.mergeFields({1: 2}, {3: 4}));
assertArrayEquals({}, cal.mergeFields({true: 2}, {false: 4}));
assertArrayEquals({}, cal.mergeFields({1n: 2}, {2n: 4}));
assertArrayEquals({}, cal.mergeFields({Infinity: 2}, {Infinity: 4}));
assertArrayEquals({}, cal.mergeFields({undefined: 2}, {NaN: 4}));
assertArrayEquals({}, cal.mergeFields({["foo"]: 2}, {["bar"]: 4}));
assertArrayEquals({a:1, b:2, c:4}, cal.mergeFields({a: 1, b: 2}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, month:5, month:'M06'},
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:'M06'}, cal.mergeFields({a: 1, b: 2},
{b:3, c:4, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'},
{b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'},
{b:3, c:4, monthCode:'M06'}));
assertArrayEquals({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'}));
assertArrayEquals({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'}));
assertArrayEquals({a:1, b:2, c:4, month:7},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:5, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:7, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, monthCode:'M08'}, {b:3, c:4}));