Test PlainYearMonth.compare.

This commit is contained in:
Ms2ger 2022-02-01 11:58:02 +01:00 committed by Rick Waldron
parent 6ba72412ab
commit 405f4fac4b
5 changed files with 71 additions and 1 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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);

View File

@ -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]
---*/