Temporal: More baseline order-of-operations tests

Add order-of-operations tests for:

- Temporal.ZonedDateTime.p.getISOFields()
- Temporal.ZonedDateTime.p.round()
- years with ZonedDateTime relativeTo in Temporal.Duration.p.round()
- years with ZonedDateTime relativeTo in Temporal.Duration.p.total()
- property Gets on receiver in Temporal.PlainDateTime.p.with()
- ZonedDateTime difference methods with largestUnit being a time unit
- Duration.compare with no units higher than hours
This commit is contained in:
Philip Chimento 2023-03-02 12:23:51 -08:00 committed by Ms2ger
parent 56fe761577
commit c03a58ba35
8 changed files with 293 additions and 23 deletions

View File

@ -171,6 +171,30 @@ Temporal.Duration.compare(
assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo and no calendar units");
actual.splice(0); // clear
// code path through UnbalanceDurationRelative that balances higher units down
// to days:
const expectedOpsForPlainDayBalancing = expectedOpsForPlainRelativeTo.concat(
[
// UnbalanceDurationRelative
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
// UnbalanceDurationRelative again for the second argument:
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
]
);
Temporal.Duration.compare(
createDurationPropertyBagObserver("one", 1, 1, 1),
createDurationPropertyBagObserver("two", 1, 1, 1, 1),
createOptionsObserver(plainRelativeTo)
);
assert.compareArray(actual, expectedOpsForPlainDayBalancing, "order of operations with PlainDate relativeTo and calendar units");
actual.splice(0); // clear
const expectedOpsForZonedRelativeTo = expected.concat([
// ToRelativeTemporalObject
"get options.relativeTo.calendar",
@ -240,6 +264,9 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]);
const expectedOpsForCalculateOffsetShift = [
// CalculateOffsetShift on first argument
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
@ -264,7 +291,7 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]);
];
const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
year: 2001,
@ -282,33 +309,66 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
timeZone: TemporalHelpers.timeZoneObserver(actual, "options.relativeTo.timeZone"),
}, "options.relativeTo");
// order of observable operations with zoned relativeTo and without calendar units
// order of observable operations with zoned relativeTo and without calendar units except days
Temporal.Duration.compare(
createDurationPropertyBagObserver("one", 0, 0, 0, 7),
createDurationPropertyBagObserver("two", 0, 0, 0, 6),
createOptionsObserver(zonedRelativeTo)
);
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo and no calendar units");
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat(expectedOpsForCalculateOffsetShift),
"order of operations with ZonedDateTime relativeTo and no calendar units except days"
);
actual.splice(0); // clear
// order of observable operations with zoned relativeTo and with only time units
Temporal.Duration.compare(
createDurationPropertyBagObserver("one", 0, 0, 0, 0, 7),
createDurationPropertyBagObserver("two", 0, 0, 0, 0, 6),
createOptionsObserver(zonedRelativeTo)
);
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
// CalculateOffsetShift on first arg
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// CalculateOffsetShift on second arg
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]),
"order of operations with ZonedDateTime relativeTo and only time units"
);
actual.splice(0); // clear
// code path through UnbalanceDurationRelative that balances higher units down
// to days:
const expectedOpsForDayBalancing = expectedOpsForZonedRelativeTo.concat([
// UnbalanceDurationRelative
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7.a ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
// UnbalanceDurationRelative again for the second argument:
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7.a ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
]);
const expectedOpsForDayBalancing = expectedOpsForZonedRelativeTo.concat(
expectedOpsForCalculateOffsetShift,
[
// UnbalanceDurationRelative
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7.a ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
// UnbalanceDurationRelative again for the second argument:
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7.a ToTemporalDate
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 11.a.ii
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
]
);
Temporal.Duration.compare(
createDurationPropertyBagObserver("one", 1, 1, 1),
createDurationPropertyBagObserver("two", 1, 1, 1, 1),

View File

@ -351,3 +351,44 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
// basic order of operations with ZonedDateTime relativeTo:
instance.round(createOptionsObserver({ relativeTo: zonedRelativeTo }));
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateUntil", // 12. DifferenceISODateTime
"call options.relativeTo.calendar.dateUntil",
// NanosecondsToDays → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// NanosecondsToDays → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e
"call options.relativeTo.calendar.dateAdd", // 9.j
"get options.relativeTo.calendar.dateUntil", // 9.m
"call options.relativeTo.calendar.dateUntil", // 9.m
"call options.relativeTo.calendar.dateAdd", // 9.r
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
]);
instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo }));
assert.compareArray(
actual,
expectedOpsForYearRoundingZoned,
"order of operations with smallestUnit = years and ZonedDateTime relativeTo"
);
actual.splice(0); // clear

View File

@ -235,9 +235,6 @@ const expectedOpsForZonedRelativeTo = [
"get options.unit",
"get options.unit.toString",
"call options.unit.toString",
// RoundDuration → ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
];
const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
@ -258,4 +255,63 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
// basic order of observable operations, without rounding:
instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zonedRelativeTo }));
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
// RoundDuration → ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]),
"order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// BalancePossiblyInfiniteDuration → NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateUntil", // 12. DifferenceISODateTime
"call options.relativeTo.calendar.dateUntil",
// BalancePossiblyInfiniteDuration → NanosecondsToDays → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// BalancePossiblyInfiniteDuration → NanosecondsToDays → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
], [
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// code path through RoundDuration that rounds to the nearest year:
// MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e
"call options.relativeTo.calendar.dateAdd", // 9.j
"get options.relativeTo.calendar.dateUntil", // 9.m
"call options.relativeTo.calendar.dateUntil", // 9.m
"call options.relativeTo.calendar.dateAdd", // 9.r
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
]);
instance.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo }));
assert.compareArray(
actual,
expectedOpsForYearRoundingZoned,
"order of operations with unit = years and ZonedDateTime relativeTo"
);
actual.splice(0); // clear

View File

@ -18,10 +18,16 @@ const expected = [
// PrepareTemporalFields on receiver
"get this.calendar.day",
"call this.calendar.day",
"get this.hour",
"get this.microsecond",
"get this.millisecond",
"get this.minute",
"get this.calendar.month",
"call this.calendar.month",
"get this.calendar.monthCode",
"call this.calendar.monthCode",
"get this.nanosecond",
"get this.second",
"get this.calendar.year",
"call this.calendar.year",
// PrepareTemporalFields on argument
@ -76,6 +82,13 @@ const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 32
// clear observable operations that occurred during the constructor call
actual.splice(0);
TemporalHelpers.observeProperty(actual, instance, "hour", 12, "this");
TemporalHelpers.observeProperty(actual, instance, "minute", 34, "this");
TemporalHelpers.observeProperty(actual, instance, "second", 56, "this");
TemporalHelpers.observeProperty(actual, instance, "millisecond", 987, "this");
TemporalHelpers.observeProperty(actual, instance, "microsecond", 654, "this");
TemporalHelpers.observeProperty(actual, instance, "nanosecond", 321, "this");
const fields = TemporalHelpers.propertyBagObserver(actual, {
year: 1.7,
month: 1.7,

View File

@ -0,0 +1,31 @@
// 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.zoneddatetime.prototype.getisofields
description: >
Properties on the calendar or time zone of the receiver of getISOFields()
are accessed in the correct order
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
];
const actual = [];
const instance = new Temporal.ZonedDateTime(
988786472_987_654_321n, /* 2001-05-02T06:54:32.987654321Z */
TemporalHelpers.timeZoneObserver(actual, "this.timeZone"),
TemporalHelpers.calendarObserver(actual, "this.calendar"),
);
// clear any observable operations that happen due to time zone or calendar
// calls on the constructor
actual.splice(0);
instance.getISOFields();
assert.compareArray(actual, expected, "order of operations");

View File

@ -0,0 +1,61 @@
// 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.zoneddatetime.prototype.equals
description: Properties on objects passed to equals() are accessed in the correct order
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"get options.roundingIncrement",
"get options.roundingIncrement.valueOf",
"call options.roundingIncrement.valueOf",
"get options.roundingMode",
"get options.roundingMode.toString",
"call options.roundingMode.toString",
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
// GetPlainDateTimeFor on receiver's instant
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// GetInstantFor on preceding midnight
"get this.timeZone.getPossibleInstantsFor",
"call this.timeZone.getPossibleInstantsFor",
// AddZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
"get this.calendar.dateAdd",
"call this.calendar.dateAdd",
"get this.timeZone.getPossibleInstantsFor",
"call this.timeZone.getPossibleInstantsFor",
// GetOffsetNanosecondsFor
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// InterpretISODateTimeOffset
"get this.timeZone.getPossibleInstantsFor",
"call this.timeZone.getPossibleInstantsFor",
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
];
const actual = [];
const options = TemporalHelpers.propertyBagObserver(actual, {
smallestUnit: "nanoseconds",
roundingMode: "halfExpand",
roundingIncrement: 1,
}, "options");
const instance = new Temporal.ZonedDateTime(
988786472_987_654_321n, /* 2001-05-02T06:54:32.987654321Z */
TemporalHelpers.timeZoneObserver(actual, "this.timeZone"),
TemporalHelpers.calendarObserver(actual, "this.calendar"),
);
// clear any observable operations that happen due to time zone or calendar
// calls on the constructor
actual.splice(0);
instance.round(options);
assert.compareArray(actual, expected, "order of operations");

View File

@ -247,3 +247,7 @@ const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDiffere
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
actual.splice(0); // clear
instance.since(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "hours" }));
assert.compareArray(actual, expected, "order of operations with largestUnit being a time unit");
actual.splice(0); // clear

View File

@ -247,3 +247,7 @@ const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDiffere
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
actual.splice(0); // clear
instance.until(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "hours" }));
assert.compareArray(actual, expected, "order of operations with largestUnit being a time unit");
actual.splice(0); // clear