diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 963498b909..d34fd2deda 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -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`); }, /* diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-plaindatetime.js b/test/built-ins/Temporal/PlainDate/compare/argument-plaindatetime.js index a41d6b0b08..be83e03a68 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-plaindatetime.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-plaindatetime.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-zoneddatetime.js b/test/built-ins/Temporal/PlainDate/compare/argument-zoneddatetime.js new file mode 100644 index 0000000000..1b45929bea --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/argument-zoneddatetime.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.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");