diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-cast.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-cast.js new file mode 100644 index 0000000000..eadfb0e3c0 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-cast.js @@ -0,0 +1,19 @@ +// 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.compare +description: compare() casts its arguments +features: [Temporal] +---*/ + +const nov94 = Temporal.PlainYearMonth.from("1994-11"); +const jun13 = Temporal.PlainYearMonth.from("2013-06"); + +assert.sameValue(Temporal.PlainYearMonth.compare({ year: 1994, month: 11 }, jun13), -1, "one object"); +assert.sameValue(Temporal.PlainYearMonth.compare("1994-11", jun13), -1, "one string"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.compare({ year: 1994 }, jun13), "one missing property"); + +assert.sameValue(Temporal.PlainYearMonth.compare(nov94, { year: 2013, month: 6 }), -1, "two object"); +assert.sameValue(Temporal.PlainYearMonth.compare(nov94, "2013-06"), -1, "two string"); +assert.throws(TypeError, () => Temporal.PlainYearMonth.compare(nov94, { year: 2013 }), "two missing property"); diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/basic.js b/test/built-ins/Temporal/PlainYearMonth/compare/basic.js new file mode 100644 index 0000000000..0d9799cd98 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/basic.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.compare +description: Basic tests for compare() +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(Temporal.PlainYearMonth.compare(nov94, nov94), 0, "same object"); +assert.sameValue(Temporal.PlainYearMonth.compare(nov94, nov94bis), 0, "different object"); +assert.sameValue(Temporal.PlainYearMonth.compare(nov94, jun13), -1, "before"); +assert.sameValue(Temporal.PlainYearMonth.compare(jun13, nov94), 1, "after"); diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js b/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js new file mode 100644 index 0000000000..a3b9185118 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/compare-calendar.js @@ -0,0 +1,22 @@ +// 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.compare +description: compare() does not take the calendar into account +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor(id) { + super("iso8601"); + this._id = id; + } + toString() { + return this._id; + } +} + +const ym1 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("a"), 1); +const ym2 = new Temporal.PlainYearMonth(2000, 1, new CustomCalendar("b"), 1); +assert.sameValue(Temporal.PlainYearMonth.compare(ym1, ym2), 0); diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/compare-reference-day.js b/test/built-ins/Temporal/PlainYearMonth/compare/compare-reference-day.js new file mode 100644 index 0000000000..29a9c48661 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/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.compare +description: compare() 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(Temporal.PlainYearMonth.compare(ym1, ym2), -1); diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/use-internal-slots.js b/test/built-ins/Temporal/PlainYearMonth/compare/use-internal-slots.js index 5b2fde22b2..0cde320b16 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/use-internal-slots.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/use-internal-slots.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal-sec-temporal.yearmonth.compare +esid: sec-temporal.plainyearmonth.compare description: compare() ignores the observable properties and uses internal slots features: [Temporal] ---*/