mirror of https://github.com/tc39/test262.git
Temporal: Extend tests for PlainDate.compare.
This commit is contained in:
parent
ee7055121d
commit
820461ef4b
|
@ -252,7 +252,7 @@ var TemporalHelpers = {
|
|||
* calendar object (so that it doesn't have to call the calendar getter itself
|
||||
* if it wants to make any assertions about the calendar.)
|
||||
*/
|
||||
checkPlainDateTimeConversionFastPath(func) {
|
||||
checkPlainDateTimeConversionFastPath(func, message = "checkPlainDateTimeConversionFastPath") {
|
||||
const actual = [];
|
||||
const expected = [];
|
||||
|
||||
|
@ -285,7 +285,7 @@ var TemporalHelpers = {
|
|||
});
|
||||
|
||||
func(datetime, calendar);
|
||||
assert.compareArray(actual, expected, "property getters not called");
|
||||
assert.compareArray(actual, expected, `${message}: property getters not called`);
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -15,14 +15,36 @@ includes: [compareArray.js, temporalHelpers.js]
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const sameDate = new Temporal.PlainDate(2000, 5, 2);
|
||||
const earlierDate = new Temporal.PlainDate(1920, 7, 3);
|
||||
const laterDate = new Temporal.PlainDate(2005, 1, 12);
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(datetime, date);
|
||||
assert.sameValue(result, 0, "comparison result");
|
||||
});
|
||||
const result = Temporal.PlainDate.compare(datetime, sameDate);
|
||||
assert.sameValue(result, 0, "First argument, same date: comparison result");
|
||||
}, "First argument, same date");
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(date, datetime);
|
||||
assert.sameValue(result, 0, "comparison result");
|
||||
});
|
||||
const result = Temporal.PlainDate.compare(datetime, earlierDate);
|
||||
assert.sameValue(result, 1, "First argument, earlier date: comparison result");
|
||||
}, "First argument, earlier date");
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(datetime, laterDate);
|
||||
assert.sameValue(result, -1, "First argument, later date: comparison result");
|
||||
}, "First argument, later date");
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(sameDate, datetime);
|
||||
assert.sameValue(result, 0, "Second argument, same date: comparison result");
|
||||
}, "Second argument, same date");
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(earlierDate, datetime);
|
||||
assert.sameValue(result, -1, "Second argument, earlier date: comparison result");
|
||||
}, "Second argument, earlier date");
|
||||
|
||||
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
|
||||
const result = Temporal.PlainDate.compare(laterDate, datetime);
|
||||
assert.sameValue(result, 1, "Second argument, later date: comparison result");
|
||||
}, "Second argument, later date");
|
||||
|
|
|
@ -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.plaindate.compare
|
||||
description: ZonedDateTime is supported.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
assert.sameValue(
|
||||
Temporal.PlainDate.compare(zdt, new Temporal.PlainDate(1970, 1, 1)),
|
||||
0, "same date, ZDT first");
|
||||
assert.sameValue(
|
||||
Temporal.PlainDate.compare(zdt, new Temporal.PlainDate(1970, 1, 1)),
|
||||
0, "same date, ZDT second");
|
||||
assert.sameValue(
|
||||
Temporal.PlainDate.compare(zdt, new Temporal.PlainDate(1976, 11, 18)),
|
||||
-1, "different date, ZDT first");
|
||||
assert.sameValue(
|
||||
Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), zdt),
|
||||
1, "different date, ZDT second");
|
Loading…
Reference in New Issue