mirror of https://github.com/tc39/test262.git
Add tests for PlainDate#equals().
This commit is contained in:
parent
0855621088
commit
78b8f7945c
20
test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-invalid.js
vendored
Normal file
20
test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-invalid.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.equals
|
||||||
|
description: Appropriate error thrown when object argument is invalid
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 });
|
||||||
|
|
||||||
|
// End up in ISODateFromFields with missing fields
|
||||||
|
assert.throws(TypeError, () => instance.equals({}), "plain object");
|
||||||
|
assert.throws(TypeError, () => instance.equals({ year: 1972, month: 7 }), "only year, month");
|
||||||
|
assert.throws(TypeError, () => instance.equals({ year: 1972, month: 7 }), "only year, month");
|
||||||
|
assert.throws(TypeError, () => instance.equals({ year: 1972, day: 7 }), "only year, day");
|
||||||
|
assert.throws(TypeError, () => instance.equals(Temporal.PlainDate), "Temporal.PlainDate");
|
||||||
|
|
||||||
|
// Tries to get fields with an invalid receiver
|
||||||
|
assert.throws(TypeError, () => instance.equals(Temporal.PlainDate.prototype), "Temporal.PlainDate.prototype");
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.equals
|
||||||
|
description: equals with a valid property bag
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||||
|
assert.sameValue(instance.equals({ year: 2000, month: 5, day: 2 }), true, "same date");
|
||||||
|
assert.sameValue(instance.equals({ year: 2000, month: 5, day: 4 }), false, "different date");
|
||||||
|
|
||||||
|
const calendar = { toString() { return "a" } };
|
||||||
|
assert.sameValue(instance.withCalendar(calendar).equals({ year: 2000, month: 5, day: 2 }),
|
||||||
|
false, "different calendar");
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.equals
|
||||||
|
description: equals with a valid string
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||||
|
assert.sameValue(instance.equals("2000-05-02"), true, "same date");
|
||||||
|
assert.sameValue(instance.equals("2000-05-04"), false, "different date");
|
||||||
|
|
||||||
|
const calendar = { toString() { return "a" } };
|
||||||
|
assert.sameValue(instance.withCalendar(calendar).equals("2000-05-02"), false, "different calendar");
|
|
@ -15,6 +15,3 @@ assert.throws(RangeError, () => instance.equals(true), "true");
|
||||||
assert.throws(RangeError, () => instance.equals(""), "empty string");
|
assert.throws(RangeError, () => instance.equals(""), "empty string");
|
||||||
assert.throws(TypeError, () => instance.equals(Symbol()), "symbol");
|
assert.throws(TypeError, () => instance.equals(Symbol()), "symbol");
|
||||||
assert.throws(RangeError, () => instance.equals(1), "1");
|
assert.throws(RangeError, () => instance.equals(1), "1");
|
||||||
assert.throws(TypeError, () => instance.equals({}), "plain object");
|
|
||||||
assert.throws(TypeError, () => instance.equals(Temporal.PlainDate), "Temporal.PlainDate");
|
|
||||||
assert.throws(TypeError, () => instance.equals(Temporal.PlainDate.prototype), "Temporal.PlainDate.prototype");
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.protoype.equals
|
||||||
|
description: basic tests
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const date1 = new Temporal.PlainDate(1976, 11, 18);
|
||||||
|
const date2 = new Temporal.PlainDate(1914, 2, 23);
|
||||||
|
const date3 = new Temporal.PlainDate(1914, 2, 23);
|
||||||
|
assert.sameValue(date1.equals(date2), false, "different dates");
|
||||||
|
assert.sameValue(date2.equals(date3), true, "same dates");
|
||||||
|
assert.sameValue(date2.equals(date2), true, "same objects");
|
30
test/built-ins/Temporal/PlainDate/prototype/equals/calendar-call-different.js
vendored
Normal file
30
test/built-ins/Temporal/PlainDate/prototype/equals/calendar-call-different.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.protoype.equals
|
||||||
|
description: test if the calendar is compared
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CalendarTraceToString extends Temporal.Calendar {
|
||||||
|
constructor(id) {
|
||||||
|
super("iso8601");
|
||||||
|
this.id_ = id;
|
||||||
|
this.calls = 0;
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
++this.calls;
|
||||||
|
return this.id_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendar1 = new CalendarTraceToString("a");
|
||||||
|
const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1);
|
||||||
|
|
||||||
|
const calendar2 = new CalendarTraceToString("b");
|
||||||
|
const date2 = new Temporal.PlainDate(1914, 2, 23, calendar2);
|
||||||
|
|
||||||
|
assert.sameValue(date1.equals(date2), false, "different calendars");
|
||||||
|
assert.sameValue(calendar1.calls, 1, "calendar1 toString() calls");
|
||||||
|
assert.sameValue(calendar2.calls, 1, "calendar2 toString() calls");
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.protoype.equals
|
||||||
|
description: test if the calendar is compared
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CalendarTraceToString extends Temporal.Calendar {
|
||||||
|
constructor(id) {
|
||||||
|
super("iso8601");
|
||||||
|
this.id_ = id;
|
||||||
|
this.calls = 0;
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
++this.calls;
|
||||||
|
return this.id_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendar1 = new CalendarTraceToString("a");
|
||||||
|
const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1);
|
||||||
|
|
||||||
|
const calendar2 = new CalendarTraceToString("a");
|
||||||
|
const date2 = new Temporal.PlainDate(1914, 2, 23, calendar2);
|
||||||
|
|
||||||
|
assert.sameValue(date1.equals(date2), true, "same calendar id");
|
||||||
|
assert.sameValue(calendar1.calls, 1, "calendar1 toString() calls");
|
||||||
|
assert.sameValue(calendar2.calls, 1, "calendar2 toString() calls");
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.protoype.equals
|
||||||
|
description: test if the calendar is compared
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class CalendarTraceToString extends Temporal.Calendar {
|
||||||
|
constructor(id) {
|
||||||
|
super("iso8601");
|
||||||
|
this.id_ = id;
|
||||||
|
this.calls = 0;
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
++this.calls;
|
||||||
|
return this.id_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendar1 = new CalendarTraceToString("a");
|
||||||
|
const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1);
|
||||||
|
|
||||||
|
const calendar2 = new CalendarTraceToString("b");
|
||||||
|
const date2 = new Temporal.PlainDate(1914, 2, 22, calendar2);
|
||||||
|
|
||||||
|
assert.sameValue(date1.equals(date2), false, "different ISO dates");
|
||||||
|
assert.sameValue(calendar1.calls, 0, "calendar1 toString() calls");
|
||||||
|
assert.sameValue(calendar2.calls, 0, "calendar2 toString() calls");
|
Loading…
Reference in New Issue