Commit Graph

159 Commits

Author SHA1 Message Date
Philip Chimento ea11e0e787 Temporal: Further coverage and tweaks for removing Calendar/TimeZone objs
Tweak some tests to provide coverage of new execution paths in the spec,
such as calling GetOptionsObject inside ToTemporal___; add a few new tests
for things that weren't covered before, such as rounding a PlainDateTime
at the edge of the range; and tweak the tests verifying when the
properties of the options bag are read, which I made a mistake in #4119.

See: https://github.com/tc39/proposal-temporal/pull/2925
2024-08-22 14:00:43 -07:00
Philip Chimento 3a7a72aef5 Temporal: Add tests for conversion of calendar and time zone IDs in constructors
Now that we don't have to deal with strings or objects as input to the
calendar ID or time zone ID parameter of constructors, we accept only the
data that actually goes into the internal slots.
2024-07-05 10:43:53 +02:00
Philip Chimento efc7424844 Temporal: Don't use getISOFields() in other tests
Previously getISOFields() was used to get the exact value of the
[[Calendar]] and [[TimeZone]] internal slots, as well as to get the
reference ISO year for PlainMonthDay and reference ISO day for
PlainYearMonth.

Use calendarId and timeZoneId for the former and toString() for the
latter.
2024-07-05 10:43:53 +02:00
Philip Chimento 7e4de57437 Temporal: Remove tests for getISOFields methods 2024-07-05 10:43:53 +02:00
Philip Chimento e5ef51ba7e Temporal: Move tests into intl402/ that require non-ISO calendar or non-UTC time zone
Without custom calendars and time zones there are actually a bunch of
things that we now can't test on implementations that don't have non-ISO
calendars or non-UTC time zones. (Alternatively, we can say that these are
functionalities that those implementations don't have to implement.)
2024-07-05 10:43:53 +02:00
Philip Chimento 9671c4a613 Temporal: Test adjustments for removing calendar and time zone objects 2024-07-05 10:43:53 +02:00
Philip Chimento 5cd7e9077d Temporal: Remove calendar and time zone observers
These are no longer possible without custom objects. Also add an exception
for calendar and timeZone properties in property bag observers so they are
not treated as objects.
2024-07-05 10:43:53 +02:00
Philip Chimento 372527e572 Temporal: Don't pass custom calendar in helper tests
This is no longer necessary if there are no calendar objects.
2024-07-05 10:43:53 +02:00
Philip Chimento 9c6734f39b Temporal: Remove Calendar and TimeZone objects from "wrong-type" tests
Test the "wrong type of object" with Duration objects where appropriate,
otherwise just use plain objects.
2024-07-05 10:43:53 +02:00
Philip Chimento debd22a2ad Temporal: Remove tests that throw on calendar or time zone method accesses
Many tests tested some functionality while asserting that there were no
calls of calendar or time zone methods. We can continue testing the
functionality, but there are no more methods to call, so we can delete
those parts of the tests.
2024-07-05 10:43:53 +02:00
Philip Chimento c728e6d89e Temporal: Fix tests that unnecessarily create TimeZone or Calendar instances
In many cases we created a TimeZone or Calendar instance from a built-in
time zone or calendar. These tests can be trivially adapted to just use
the string ID.
2024-07-05 10:43:53 +02:00
Philip Chimento ea2268aa43 Temporal: Remove tests directly relating to custom calendar and time zones
These are tests that just won't apply anymore without custom calendars and
time zones.
2024-07-05 10:43:53 +02:00
Philip Chimento 1213ab17ec Temporal: Remove getCalendar and getTimeZone methods
Temporarily replace them with getISOFields().calendar/timeZone just to
keep the tests running until we remove Calendar and TimeZone objects
altogether.

See: tc39/proposal-temporal#2826
2024-07-05 10:43:53 +02:00
Philip Chimento 3f805a1383 Temporal: Test calendar canonicalization in Temporal
Following the upstream ECMA-402 change tested in the previous commit, add
test coverage for the corresponding functionality in Temporal. Fix one
test that was erroneous.
2024-07-04 11:14:16 +02:00
Philip Chimento 6626b60df6 Temporal: Make U+2212 MINUS SIGN invalid in ISO strings
These are the test adjustments corresponding to the normative PR
https://github.com/tc39/ecma262/pull/3334 which reached consensus at the
June 2024 TC39 meeting.
2024-07-03 08:50:57 -07:00
Philip Chimento 96e31e7e28 Temporal: Tests for round() and since()/until() using the same code path
This should produce all the same results (except for a change to weeks
balancing in round(), which is now more consistent with since()/until())
but leads to different observable user code calls.

See https://github.com/tc39/proposal-temporal/issues/2742
2024-05-14 09:24:12 +02:00
Philip Chimento a074d97c5b Temporal: Tests for conversion of ISO 8601 string to ISO 8601 calendar
See https://github.com/tc39/proposal-temporal/issues/2105. This was not
covered yet in test262.
2024-04-03 12:32:46 +02:00
Philip Chimento a8da70622d Temporal: Tests for calendar.dateFromFields options in PYM/PMD.toPlainDate
It was previously not tested what options value a custom calendar's
dateFromFields() method would be called with, when called from the
toPlainDate() method of PlainYearMonth/PlainMonthDay.

See tc39/proposal-temporal#2803
2024-04-03 12:32:46 +02:00
Philip Chimento b4b574fca1 Temporal: argument-propertybag-calendar-year-zero testing the wrong thing
These tests were supposed to test an invalid ISO string being used as the
`calendar` property in a property bag. Instead they were testing being
used as an invalid ISO string directly where a PlainDate input was needed.
(That is also already covered elsewhere.)
2024-04-03 12:32:46 +02:00
Philip Chimento 0cb219ffe0 Temporal: Fix argument-propertybag-calendar-number testing the wrong methods
Due to overlooked copy-paste errors we were creating the wrong type of
instance in these tests, and therefore testing the wrong method.

(Add blank line for consistency with the other instances of these tests.)
2024-04-03 12:32:46 +02:00
Philip Chimento 0c12b84244 Temporal: Add tests for incorrectly capitalized annotation keys
As per IETF, annotation keys may only consist of lowercase letters,
dashes, and digits, and an optional leading underscore. Uppercase letters
are non-syntactical. Add tests covering this.
2024-04-03 12:32:46 +02:00
Philip Chimento 99d5bc8c1b Temporal: Limit duration years, months, and weeks to <2³² each 2024-01-31 08:22:05 -08:00
Philip Chimento 092337c8d0 Temporal: Adapt tests to upper bound on time portion of durations
Adapts or removes tests that relied on creating durations that are now out
of range. Adds new tests for maximum in-range and minimum out-of-range
durations.
2024-01-31 08:22:05 -08:00
Philip Chimento 6cbb6da947 Temporal: Change overflow behaviour of PYM/PMD.toPlainDate
These tests cover the proposed normative change:
https://github.com/tc39/proposal-temporal/issues/2706
2023-12-04 14:59:58 -08:00
Philip Chimento 27a7501893 Temporal: Limit year, month, and week length calculations to nonzero
Tests with conditions that would trip a division by zero in
implementations if they didn't carefully implement the spec.
2023-11-16 11:08:42 -08:00
Philip Chimento e43e20a885 Temporal: Remove BigInt arithmetic and loops in BalanceDurationRelative
A few results change because the algorithm previously used for rounding
didn't always add duration units to dates in RFC 5545 order, and we also
introduce a special case for rounding with largestUnit years or months and
smallestUnit weeks.
2023-11-16 11:08:42 -08:00
Philip Chimento dc1c787cc8 Temporal: Make calendar method lookups unconditional
See https://github.com/tc39/proposal-temporal/issues/2724
2023-11-14 11:44:00 -08:00
Philip Chimento 7c41695f78 Adjustments to tests for added invocations of BalanceDurationRelative
In order to fix tc39/proposal-temporal#2563, we added invocations of
BalanceDurationRelative after some invocations of RoundDuration. These
cause observable calendar calls, which must be accounted for in some
existing tests.
2023-11-14 10:03:45 -08:00
Philip Chimento 93304c7571 Tests for Duration rounding bug when rounding crosses a unit boundary
See https://github.com/tc39/proposal-temporal/issues/2563

The old behaviour was encoded in one test in staging, but the behaviour of
largestUnit in duration rounding has changed since that test was written.
Therefore I'm assuming that toString() should've been updated when that
happened.
2023-11-14 10:03:45 -08:00
Philip Chimento c5dd01f7c0 Temporal: Look up calendar methods only once 2023-11-06 14:46:36 -08:00
Philip Chimento 96bc38f5d9 Temporal: Exhaustive coverage for compare() methods
This adds coverage for each possible outcome of compare(), where each unit
is greater, lesser, or equal.
2023-10-18 09:27:24 -07:00
Philip Chimento 70c36b6584 Temporal: Tests for dates out-of-range when finding end of month
In PlainYearMonth arithmetic, we need to find the end of the month when
adding a negative duration or subtracting a positive one. This end of the
month can be out of range.

Test case based on one provided by Anba. See issue:
https://github.com/tc39/proposal-temporal/issues/2700
2023-10-18 09:27:24 -07:00
Philip Chimento 9b8d9cf66c Temporal: Fast-path dateUntil() when difference largest unit is days
This removes several loopholes where it was possible to return particular
values from user calls that would cause infinite loops, or calculate
zero-length days.
2023-10-04 15:35:39 -07:00
Philip Chimento 7a3944c0cc Temporal: Fast-path differences between identical objects 2023-10-04 15:35:39 -07:00
Philip Chimento 34ce4bd53a Temporal: Fast-path dateAdd() when adding only days 2023-10-04 15:35:39 -07:00
Philip Chimento da3dd8802f Temporal: Avoid calendar operations when adding days-only duration to PlainDate 2023-10-04 15:35:39 -07:00
Philip Chimento a74fbada42 Temporal: Don't observably iterate array in built-in calendar's fields()
Note the monkeypatch of getPossibleInstantsFor in test/built-ins/Temporal/
TimeZone/prototype/getInstantFor/argument-builtin-calendar-no-array-
iteration.js.

Other than that, all the tests are basically identical.
2023-09-13 10:57:43 +02:00
Philip Chimento f44bbe4035 Temporal: Avoid calling user code in no-op round operations
This shortcut path now exists in all round(), since(), and until()
operations.
In Instant, PlainDate, PlainDateTime, and PlainTime, the change isn't
observable, so no tests could be added. This adds test coverage for

- Duration.p.round()
- PlainYearMonth.p.since()
- PlainYearMonth.p.until()
- ZonedDateTime.p.round()
- ZonedDateTime.p.since()
- ZonedDateTime.p.until()

As well as a few cases where we are testing that certain calendar methods
get called during a round operation, but previously were doing so with
options that now become a no-op and no longer call those calendar methods.
In those cases, round to 2 ns, rather than 1 ns.
2023-09-13 10:57:43 +02:00
Philip Chimento ce92940645 Temporal: Improve various assertion messages
Some of these were overlooked in a recent big refactor.
2023-09-08 09:38:14 -07:00
Philip Chimento c30aff08af Temporal: Copy options object in Plain{Date,MonthDay,YearMonth}.{from,p.with} 2023-08-16 14:49:15 -07:00
Justin Grant 60e475248d Tests for Temporal PR #2574
Edits Temporal tests to account for changes in
https://github.com/tc39/proposal-temporal/pull/2574.

This PR stops coercing non-string primitive inputs to strings
in Temporal methods, to avoid cases where numbers
are coerced to syntactically valid but often unexpected
string results.
2023-07-18 17:09:04 +02:00
Guillaume Emont 016e4bf8e8
Temporal Issue 2532 (#3858)
* Add tests for the new PrepareTemporalFields behavior for all direct callers

See https://github.com/tc39/proposal-temporal/pull/2570

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToTemporalDate

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToTemporalDateTime

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToTemporalZonedDateTime

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToTemporalYearMonth

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToTemporalMonthDay

* Add tests for the new PrepareTemporalFields behavior for indirect callers through ToRelativeTemporalObject

* Add tests for the new PrepareTemporalFields behavior for indirect callers through AddDurationToOrSubtractDurationFromPlainYearMonth
2023-07-17 07:55:34 -07:00
Philip Chimento 3e858ef02d Tests for multiple calendar annotations with at least one critical
As per IETF review, an IXDTF string (ISO 8601 with annotations) is no
longer valid if it contains more than one u-ca annotation and at least one
of the annotations is marked critical.

Removes tests where such a string was assumed to be valid, and adds new
ones with a few variations on invalid strings.
2023-05-24 13:12:40 -07:00
Guillaume Emont 72c0c5e163 Added new tests to reflect the change that daysInMonth is the count of days in a month
This change affects how PlainYearMonth's add and subtract behave. They
now ignore daysInMonth reimplementations in the calendar, and they call
dateadd() a different number of times.

See https://github.com/tc39/proposal-temporal/issues/1315
2023-04-28 12:16:41 -07:00
Guillaume Emont d7fa398364 Updated tests to reflect that daysInMonth are the count of days in a month
See https://github.com/tc39/proposal-temporal/issues/1315
2023-04-28 12:16:41 -07:00
Philip Chimento 33865c5339 Validate required methods of Temporal Calendar protocol
Checking whether an object implements the Calendar protocol is now done by
means of HasProperty operations for each of the required methods unless
the object already has the Calendar brand.

Discussion:
https://github.com/tc39/proposal-temporal/issues/2104#issuecomment-1409549753

Corresponding normative PR:
https://github.com/tc39/proposal-temporal/pull/2485
2023-04-10 08:36:08 -07:00
Philip Chimento bc979c51a5 Remove support for nested Temporal calendar property bags
Previously, "nested" calendar property bags were unwrapped up to one
level. That is, this object:
{
  calendar: {
     // ...Temporal.Calendar methods
  }
}
would not be considered to implement the Calendar protocol, but would have
its calendar property used instead, if it were passed to an API that
required a Calendar protocol object.

These nested property bags are no longer supported. Discussion:
https://github.com/tc39/proposal-temporal/issues/2104#issuecomment-1409549753

Corresponding normative PR:
https://github.com/tc39/proposal-temporal/pull/2485
2023-04-10 08:36:08 -07:00
Philip Chimento aee3a937dc Change Temporal.Calendar compare semantics to use .id
Compare semantics for custom calendars that _don't_ extend
Temporal.Calendar (and therefore don't have the internal slot) use the
value of the .id property, instead of calling toString().

Normative PR: https://github.com/tc39/proposal-temporal/pull/2482
2023-04-07 11:43:31 -07:00
Philip Chimento 41ffc678b0 Store strings or objects in Temporal objects' [[Calendar]] slot
In several tests involving custom calendars, we need to change the
implementation of dateFromFields/monthDayFromFields/yearMonthFromFields so
that the returned object gets the receiver as its calendar after chaining
up to the builtin implementation.

Normative PR: https://github.com/tc39/proposal-temporal/pull/2482
2023-04-07 11:43:31 -07:00
Philip Chimento a1bf99771c Replace Temporal objects' .calendar getters with .calendarId/.getCalendar
This is the replacement of the old API with the new API. Semantics will be
corrected in the following commit.

Normative PR: https://github.com/tc39/proposal-temporal/pull/2482
2023-04-07 11:43:31 -07:00