From 56430e839fbd967338496a5c1f1cb5cf76d53519 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 12:08:18 -0700 Subject: [PATCH] Add tests for Temporal.Calendar.p*.mergeFields --- .../Calendar/prototype/mergeFields/simple.js | 26 ++++++++++ .../mergeFields/throws-type-error.js | 31 ++++++++++++ .../prototype/mergeFields/with-month.js | 50 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/mergeFields/simple.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/mergeFields/throws-type-error.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/mergeFields/with-month.js diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/simple.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/simple.js new file mode 100644 index 00000000000..35461df5bf2 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/simple.js @@ -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}))); diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/throws-type-error.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/throws-type-error.js new file mode 100644 index 00000000000..4893d14b0d7 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/throws-type-error.js @@ -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 diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/with-month.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/with-month.js new file mode 100644 index 00000000000..191734fdfbb --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/with-month.js @@ -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})));