From ab6fab987e20095ba351103a27115239b49158f1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 1 Feb 2022 15:15:14 +0100 Subject: [PATCH] Test PlainYearMonth.prototype.equals. --- .../prototype/equals/argument-cast.js | 16 +++++++ .../PlainYearMonth/prototype/equals/basic.js | 15 +++++++ .../prototype/equals/compare-calendar.js | 43 +++++++++++++++++++ .../prototype/equals/compare-reference-day.js | 13 ++++++ .../prototype/equals/use-internal-slots.js | 23 ++++++++++ 5 files changed, 110 insertions(+) create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/basic.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-reference-day.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/use-internal-slots.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast.js new file mode 100644 index 0000000000..bce5e7b3c5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-cast.js @@ -0,0 +1,16 @@ +// 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.plainyearmonth.prototype.equals +description: equals() casts its argument +features: [Temporal] +---*/ + +const nov94 = Temporal.PlainYearMonth.from("1994-11"); + +assert.sameValue(nov94.equals({ year: 2013, month: 6 }), false, "object"); +assert.sameValue(nov94.equals({ year: 1994, month: 11 }), true, "object"); +assert.sameValue(nov94.equals("2013-06"), false, "string"); +assert.sameValue(nov94.equals("1994-11"), true, "string"); +assert.throws(TypeError, () => nov94.equals({ year: 2013 }), "missing property"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/basic.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/basic.js new file mode 100644 index 0000000000..d125448ec1 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/basic.js @@ -0,0 +1,15 @@ +// 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.plainyearmonth.prototype.equals +description: Basic tests for equals() +features: [Temporal] +---*/ + +const nov94 = Temporal.PlainYearMonth.from("1994-11"); +const nov94bis = Temporal.PlainYearMonth.from("1994-11"); +const jun13 = Temporal.PlainYearMonth.from("2013-06"); +assert.sameValue(nov94.equals(nov94), true, "same object"); +assert.sameValue(nov94.equals(nov94bis), true, "different object"); +assert.sameValue(nov94.equals(jun13), false, "different year-months"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js new file mode 100644 index 0000000000..bf9cddac7e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-calendar.js @@ -0,0 +1,43 @@ +// 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.plainyearmonth.prototype.equals +description: equals() takes the calendar into account +includes: [compareArray.js] +features: [Temporal] +---*/ + +const actual = []; +class CustomCalendar extends Temporal.Calendar { + constructor(id) { + super("iso8601"); + this._id = id; + } + toString() { + actual.push(this._id); + return this._id; + } +} + +const sharedCalendar = new CustomCalendar("a"); +const ym1 = new Temporal.PlainYearMonth(2000, 1, sharedCalendar, 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, sharedCalendar, 1); +assert.sameValue(ym1.equals(ym2), true); +assert.compareArray(actual, [], "should not call toString if objects are equal"); + +const ym3 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("b"), 1); +const ym4 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("c"), 2); +assert.sameValue(ym3.equals(ym4), false); +assert.compareArray(actual, [], "should not call toString if ISO dates differ"); + +const ym5 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("d"), 1); +const ym6 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("e"), 1); +assert.sameValue(ym5.equals(ym6), false); +assert.compareArray(actual, ["d", "e"], "order of operations"); + +actual.splice(0, actual.length); // empty it for the next check +const ym7 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("f"), 1); +const ym8 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("f"), 1); +assert.sameValue(ym7.equals(ym8), true); +assert.compareArray(actual, ["f", "f"], "order of operations"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-reference-day.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-reference-day.js new file mode 100644 index 0000000000..3c40f5031e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/compare-reference-day.js @@ -0,0 +1,13 @@ +// 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.plainyearmonth.prototype.equals +description: equals() takes the reference day into account +features: [Temporal] +---*/ + +const iso = Temporal.Calendar.from("iso8601"); +const ym1 = new Temporal.PlainYearMonth(2000, 1, iso, 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, iso, 2); +assert.sameValue(ym1.equals(ym2), false); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/use-internal-slots.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/use-internal-slots.js new file mode 100644 index 0000000000..64a2b96ba6 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/use-internal-slots.js @@ -0,0 +1,23 @@ +// 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.plainyearmonth.prototype.equals +description: equals() ignores the observable properties and uses internal slots +features: [Temporal] +---*/ + +function CustomError() {} + +class AvoidGettersYearMonth extends Temporal.PlainYearMonth { + get year() { + throw new CustomError(); + } + get month() { + throw new CustomError(); + } +} + +const one = new AvoidGettersYearMonth(2000, 5); +const two = new AvoidGettersYearMonth(2006, 3); +assert.sameValue(one.equals(two), false);