Commit Graph

172 Commits

Author SHA1 Message Date
Philip Chimento b5a5b283a3 Temporal: Fast-path AddDaysToZonedDateTime in AddZonedDateTime 2023-10-04 15:35:39 -07:00
Philip Chimento 8040379076 Temporal: Avoid calendar operations when adding days-only duration to ZDT
This allows removing several tests, as calendar.dateAdd() is no longer
called in several places, and it's no longer possible to create a
situation where BigInt arithmetic is observable in NanosecondsToDays.
2023-10-04 15:35:39 -07:00
Philip Chimento e98bfb332e Temporal: Do away with CalculateOffsetShift in Duration.compare 2023-09-13 10:57:43 +02:00
Philip Chimento 5972c16b07 Temporal: Return early from Duration.compare if internal slots equal 2023-09-13 10:57:43 +02:00
Philip Chimento 80958c3267 Temporal: Avoid reconverting Zoned- to PlainDateTime in AddZonedDateTime 2023-09-13 10:57:43 +02: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 fdd44e2ea5 Temporal: Separate zoned and plain operations in RoundDuration
Adds new tests to order-of-operations.js in Duration.round and
Duration.total, to exercise the code path where previous to this normative
change, relativeTo would have been converted to PlainDate 3x and 2x,
respectively.
2023-09-13 10:57:43 +02:00
Philip Chimento 008b97932b Temporal: Don't convert relativeTo to PlainDate twice in Duration.compare 2023-09-13 10:57:43 +02:00
Philip Chimento 0a6341de65 Temporal: Call user code on relativeTo only when necessary in RoundDuration 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 d4f49b84ab Temporal: Update outdated test descriptions 2023-09-08 09:38:14 -07:00
Philip Chimento 6c16577f34 Temporal: Remove unused variables
These are also leftovers from the recent refactor, I think.
2023-09-08 09:38:14 -07: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 4b4de778d4 Temporal: Limit allowed values for Calendar.fields to date units 2023-08-16 14:49:15 -07:00
Justin Grant 2e4e0e6b8e Test ISO sub-minute offsets, incl. trailing zeroes
Plugs a test hole where we were not fully testing ISO strings with
sub-minute offsets, in particular those with trailing zeroes.
2023-08-10 10:13:27 +02:00
Justin Grant 2e1d7a72ff Test rejecting ISO strings with subminute offsets
This commit verifies that ISO strings with sub-minute offsets cannot
be parsed into time zone identifiers. This was a change introduced in
the recently-merged tc39/proposal-temporal#2607, but tests for this case
were missing from #3862 (the tests for that PR).

I noticed in codecov results on an unrelated PR that this case wasn't
being tested, so fixing that mistake now.
2023-08-09 11:37:39 -07:00
Justin Grant 6f146e6f30 Limit offset time zones to minute precision
Modify/add tests for https://github.com/tc39/proposal-temporal/pull/2607
2023-07-18 17:44:19 +02: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 63e451dc80 Temporal: Tests for malicious time zones with zero-length days
Based on test cases provided by Anba in
https://github.com/tc39/proposal-temporal/issues/2333. (Thanks!)
2023-05-31 09:11:25 -07:00
Philip Chimento dd47e4e248 Improve comments and assertion messages 2023-04-24 12:14:18 +02:00
Philip Chimento c03a58ba35 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
2023-04-24 12:14:18 +02:00
Guillaume Emont da56f5e2b2 Temporal: updates tests for balancing ordering change in Temporal.Duration.prototype.round
Fixes some tests which are observing side effects of round().
2023-04-10 12:50:11 -07:00
Guillaume Emont 13778441ad Temporal: added a test reproducing tc39/proposal-temporal#2508
Before the issue is fixed, rounding a duration such as 'PT2400h' with
months as largest unit fails to balance it properly and gives a result
with days being the largest unit. The test ensures that such rounding
happens properly.
2023-04-10 12:50:11 -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 d6a24fe906 Validate required methods of Temporal TimeZone protocol
Checking whether an object implements the TimeZone protocol is now done by
means of HasProperty operations for each of the required methods unless
the object already has the TimeZone 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 24def913ec Remove support for nested Temporal time zone property bags
Previously, "nested" time zone property bags were unwrapped up to one
level. That is, this object:
{
  timeZone: {
     // ...Temporal.TimeZone methods
  }
}
would not be considered to implement the TimeZone protocol, but would have
its timeZone property used instead, if it were passed to an API that
required a TimeZone 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 960070549b Store strings or objects in Temporal.ZonedDateTime [[TimeZone]] slot
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
Aditi 1c47728a20 Remove failing tests for CalendarFields and CalendarMergeFields 2023-02-10 17:43:47 -08:00
Philip Chimento e7364ea7dc Temporal: Tests for upper limit on rounding increments
Previously in a few cases (calendar units in Duration) the value for the
roundingIncrement option had no upper limit, other than having to be
finite. These tests cover a normative change limiting it to 1e9.

Normative PR: https://github.com/tc39/proposal-temporal/pull/2480
2023-02-01 11:50:44 -08:00
Cam Tenny 09f863d8c3 Temporal operation NanosecondsToDays: Test infinite or arbitrary-length observable loops in Duration and ZonedDateTime 2023-01-03 12:47:37 -08:00
Cam Tenny f00d4118db Temporal operation NanosecondsToDays: Test RangeErrors reachable in Duration and ZonedDateTime. 2022-12-23 15:35:51 +01:00
Philip Chimento 8f752acdaa Temporal: Test order of property accesses
This contains tests for the normative PR
https://github.com/tc39/proposal-temporal/pull/2437, which is to be
presented for consensus to TC39 in the upcoming plenary meeting. That PR
changes the observable order of property accesses to be alphabetical where
possible.
2022-12-01 11:35:04 -08:00
Philip Chimento 338063f80f Temporal: Test throwing on time-zone-to-calendar conversion and vice versa
This contains tests for the normative PR
https://github.com/tc39/proposal-temporal/pull/2433, which is to be
presented for consensus to TC39 in the upcoming plenary meeting. That PR
changes ToTemporalCalendar to throw when it encounters a Temporal.TimeZone
instance, and ToTemporalTimeZone to throw when it encounters a
Temporal.Calendar instance.
2022-11-30 10:01:45 -08:00
Philip Chimento 1e9dc7f38e Temporal: Clean up existing uses of foo.splice(0, foo.length)
The second parameter isn't needed if the intention is to empty the array.
Additionally clearing it at the end of the test isn't needed.
2022-11-29 11:53:40 +01:00
Philip Chimento 47b9e32dc3 Temporal: Add some more order-of-operations tests
This adds order-of-operations tests that cover all of the Temporal entry
points that accept options bags, that were not already covered. We'll be
using these tests in the future to verify
https://github.com/tc39/proposal-temporal/issues/2254
However, the tests in this commit reflect the current state of the
proposal, not the potential normative change.
2022-11-29 11:53:40 +01:00
Philip Chimento 22e01996f3 Temporal: Expand order-of-operations tests to cover different types of relativeTo
The `relativeTo` parameter in an options bag may be undefined, a PlainDate
instance, or a ZonedDateTime instance. Each of these three possibilities
causes a different set of observable operations, which we can test in our
existing order-of-operations tests.
2022-11-29 11:53:40 +01:00
Philip Chimento 1c2508e801 Temporal: Add offset field to order-of-operations tests
There are additional observable operations that occur when providing an
`offset` property in a relativeTo or ZonedDateTime property bag. We can
test these in our existing order-of-operations tests.
2022-11-29 11:53:40 +01:00
Philip Chimento 1f59bf5911 Temporal: Add tests for fast path in ToTemporalTimeZone
Normally, a plain object passed into an API that takes a Temporal.TimeZone
has its 'timeZone' property checked (observably) with a Has operation
followed by a Get operation if the property is present. In the normative
change https://github.com/tc39/proposal-temporal/pull/2392 which reached
consensus at the September 2022 TC39 meeting, this was changed so that
this check is skipped for objects which have the Temporal.TimeZone
internal slots.

This adds tests to all entry points that pass a user-supplied object to
ToTemporalTimeZone, with a "poisoned" timeZone object which has the
correct internal slots but a 'timeZone' accessor property whose getter
throws. A correct implementation should not cause this getter to throw.
2022-10-18 14:38:38 +02:00
Philip Chimento fefa14c285 Temporal: Clarify names of some time zone tests
In these tests, we should make a distinction in the name for clarity. It's
testing a time zone passed as a property in a property bag (either as an
argument, or as a relativeTo option), so name it accordingly as we do with
other tests in the same folder.
2022-10-18 14:38:38 +02:00
Philip Chimento 77b559ce68 Temporal: Fix expectation for observable operations in Duration.p.round()
I had missed that there's an early return step from
UnbalanceDurationRelative if years, months, weeks, and days are all 0.

Closes: #3684
2022-10-17 14:29:19 +02:00
Philip Chimento 01f73e96ca Temporal: Add tests for avoiding observable iteration in CalendarFields
See https://github.com/tc39/proposal-temporal/pull/2316 which eliminated
an observable call to Array.prototype[Symbol.iterator]() in the case where
a calendar's 'fields' property was undefined.

The best way I've thought of to test this is to monkeypatch the
Array.prototype[Symbol.iterator]() method to make it throw. In some cases,
where we are actually expected to iterate the return value from a
Temporal.TimeZone's getPossibleInstantsFor() method, we have to provide a
custom method for that as well, that returns a non-Array iterable so we
don't call the patched Array.prototype[Symbol.iterator]().

This normative change reached consensus at the July 2022 TC39 plenary
meeting.
2022-10-11 12:23:47 +02:00
Philip Chimento bf3efa65fc Temporal: Adjust relativeto-string-datetime tests
As of https://github.com/tc39/proposal-temporal/pull/2397 which reached
consensus in the August 2022 TC39 meeting, a date-time + Z with no bracket
annotation is no longer accepted as a relativeTo parameter; either the Z
should be removed or a bracket annotation should be added.

This requires adjusting a few existing tests, but doesn't require any new
ones.
2022-10-11 12:19:49 +02:00
Philip Chimento eb67a7689f Temporal: Add tests for observable operations in MoveRelativeDate
See https://github.com/tc39/proposal-temporal/pull/2267 which eliminated
some unnecessary lookups of the calendar's dateAdd method from the
MoveRelativeDate AO, which is called in the calendar types' since() and
until() methods, Duration.p.round(), and Duration.p.total().

This adds tests for the order of all observable operations for these 10
methods, not just the lookups of dateAdd on the calendar. (These methods
needed to have their order of observable operations tested anyway.)

They heavily use the TemporalHelpers.calendarObserver and
TemporalHelpers.timeZoneObserver added in the previous commits.

https://github.com/tc39/proposal-temporal/pull/2267 included changes to
several code paths, not all of which are reachable through every method
tested here; only Duration.p.round() can trigger the full set.

https://github.com/tc39/proposal-temporal/pull/2267 reached consensus at
the July 2022 TC39 plenary meeting.
2022-10-05 16:53:52 +02:00
Philip Chimento 89116e95dd Temporal: Add some assertion messages to help with debugging 2022-10-03 15:58:21 -07:00
André Bargull e292fb80de Import SpiderMonkey Temporal tests
Temporal tests written for the SpiderMonkey implementation. Mostly
covers edge cases around mathematical operations and regression tests
for reported spec bugs.
2022-10-03 15:58:21 -07:00
André Bargull eaf85892fb Import SpiderMonkey Temporal tests
Temporal tests written for the SpiderMonkey implementation. Mostly
covers edge cases around mathematical operations and regression tests
for reported spec bugs.
2022-09-28 16:41:39 +02:00
Philip Chimento 8565eea8be Temporal: Test tiebreaker rounding modes more thoroughly
The "half___" modes all round to the nearest increment except when there
is a tie. The previous tests didn't test rounding in the case of any ties
(except for .toString()) so here we use some different numbers in which
there is a tie, in order to make tests where the "half___" modes are more
thoroughly tested.

See https://github.com/tc39/proposal-temporal/pull/2262 which added new
rounding modes from NumberFormat V3.
2022-09-21 11:48:28 +02:00
Philip Chimento c84e5701cd Temporal: Add tests for new rounding modes
See https://github.com/tc39/proposal-temporal/pull/2262 which added new
rounding modes from NumberFormat V3.

These tests use the same format as the previous ones. The tests for the
"half" rounding modes aren't very good yet, as they don't show any of the
differences between the tiebreaking schemes; there aren't any ties in the
data to be broken. (Except in .toString().) A subsequent commit will
correct this.
2022-09-21 11:48:28 +02:00
Philip Chimento 4155842c37 Temporal: Regularize and expand tests for round() rounding modes
Take all the existing tests for round() calculations using different
rounding modes and standardize them. Add tests for Duration, Instant and
ZonedDateTime, which were still in the old format in staging.
2022-09-21 11:48:28 +02:00
Philip Chimento 9c4aed29b7 Temporal: Remove now-valid rounding modes from roundingmode-invalid-string tests
See https://github.com/tc39/proposal-temporal/pull/2262, which reached
consensus in the July 2022 TC39 meeting. This change added several
rounding modes from the NumberFormat V3 proposal, some of which were
listed as invalid in the roundingmode-invalid-string tests. Remove these
items from the list of invalid modes, since they are no longer invalid.
2022-09-21 11:48:28 +02:00
Philip Chimento ef59ea225a Temporal: Add TemporalHelpers.propertyBagObserver()
Many existing tests use a Proxy to test the order of observable operations
on a property bag argument that gets passed in to a Temporal API. I am
going to write several more tests that do this, as well. This seems like a
good thing to put into TemporalHelpers, where it can be implemented
consistently so that we don't get discrepancies in which operations are
tracked. (For example, we had some tests which didn't test for an ownKeys
operation that was supposed to be there.)

Updates existing tests to use this helper.
2022-09-21 10:41:14 +02:00
Philip Chimento 58a9cdc426 Temporal: Test new limits for user code return from getOffsetNanosecondsFor
This tests the normative change from
https://github.com/tc39/proposal-temporal/pull/2260
which achieved consensus in the July 2022 TC39 meeting.

The return value from a userland getOffsetNanosecondsFor method is no
longer allowed to be exactly one 24-hour day.
2022-09-16 13:41:08 +02:00
Philip Chimento c4daf3ef74 Temporal: Add test for rounding Duration relative to Feb 1 in a leap year
This implements the normative change in
https://github.com/tc39/proposal-temporal/pull/2344 which reached
consensus at the July 2022 TC39 meeting.

It adds a test that catches a corner case in Duration.prototype.round().
2022-08-11 12:57:37 -07:00
Philip Chimento bc0e006de4 Temporal: Add tests for casting a time zone ID string to a Temporal.TimeZone
This adds tests to every entry point where a Temporal.TimeZone is
accepted, making sure that a time zone ID string is also accepted.
2022-08-01 13:48:11 -07:00
Philip Chimento 6b5297a142 Temporal: Add tests for invalid strings as values of 'offset' property
(...in property bags; the 'offset' option in an options object already has
tests)
2022-08-01 13:48:11 -07:00
Aditi f932f079b3 Add test for Temporal.Duration.prototype.total 2022-08-01 09:59:27 -07:00
Philip Chimento e48df0b964 Temporal: Adjust tests for non-integer/out-of-range values of fractionalSecondDigits
This implements the normative change in
https://github.com/tc39/proposal-temporal/pull/2297 which reached
consensus at the July 2022 TC39 meeting.

Values given as the fractionalSecondDigits option are now truncated to
integers before they are compared to the allowable range.
2022-07-29 15:05:41 -07:00
Aditi 6fa1bb89a3 Added tests for an empty or a function options object 2022-07-28 11:59:50 -07:00
Aditi dadf18f416 Add tests for temporalDurationLike argument and improve existing tests 2022-07-25 13:30:46 -07:00
André Bargull a3040a5047 Import SpiderMonkey Temporal tests
Temporal tests written for the SpiderMonkey implementation. Mostly
covers edge cases around mathematical operations and regression tests
for reported spec bugs.
2022-07-19 11:30:43 -07:00
Ms2ger 3ddfa0cd13 Temporal: Test that Calendar#dateAdd is called with the correct arguments. 2022-07-04 11:30:02 -06:00
Philip Chimento f314ecb9f4 Temporal: Test observable calls on fields object from PrepareTemporalFields
As of https://github.com/tc39/proposal-temporal/pull/2219 the object
returned from the PrepareTemporalFields abstract operation should be a
null-prototype object. There are a number of places where this is
observable in one of the calendar's ...FromFields() methods. This adds
tests for this behaviour everywhere it is observable.
2022-06-27 13:51:58 +02:00
Ms2ger 9762bc991f Temporal: Make branding tests more robust. 2022-06-20 13:14:35 +02:00
Ms2ger 080e893e21 Temporal: Standardize branding tests. 2022-06-20 13:14:35 +02:00
Ross Kirsling a3f09ea074 Temporal: Add missing feature flag for prototype.constructor tests. 2022-06-17 09:15:47 +02:00
André Bargull b2f7dc1194 Expect precise result for negative fractional units
Fixes #3544
2022-06-08 17:04:45 +02:00
Ms2ger 53d6cd6d46 Temporal: Add tests for converting a ZonedDateTime to a PlainDate. 2022-06-02 08:50:05 +02:00
Iban Eguia Moraza 53df4bc69a
Fixed #3545 2022-05-31 16:28:31 +02:00
Ms2ger f7b626133d Temporal: Add tests for prototype.constructor. 2022-05-26 10:34:10 +02:00
Ms2ger 6573cf954b Temporal: Add tests that subclass constructors work. 2022-05-25 11:23:22 -07:00
Ms2ger 912559f683 Temporal: Test @@toStringTag properties. 2022-05-19 12:20:15 -07:00
Ms2ger 494b678cc5 Temporal: Add tests for ZonedDateTime to PlainDate conversion.
Also rename leap second tests for consistency.
2022-05-18 12:35:07 -07:00
Ms2ger 7099acc882 Temporal: Add some tests for Duration#round.
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
2022-05-03 08:15:56 -07:00
Ms2ger 69fd39b463 Temporal: Add some Duration#{add,subtract} tests. 2022-05-03 08:15:56 -07:00
Philip Chimento 8e0e2592d3 Expand Duration.compare test
This adds coverage for the situation where we get a different answer from
Temporal.Duration.compare depending on whether relativeTo resolves to a
PlainDate or ZonedDateTime.

See discussion in
https://github.com/tc39/test262/pull/3505#discussion_r859994610
2022-05-03 08:18:02 +02:00
Philip Chimento 65a7ace1cb Regularize year zero tests
Some of these strings wouldn't have been valid even with a valid year in
them (e.g. strings ending in +01:00[UTC]) so fix up the strings that we
test. While touching these tests, I took the opportunity to regularize
them, and add some missing ones for ISO strings that convert to Calendar
and TimeZone.
2022-05-03 08:18:02 +02:00
Philip Chimento 078f3e22a4 Regularize leap second tests
Everywhere an ISO string is accepted in Temporal, a seconds value of :60
should always be coerced to :59, because of how leap seconds are handled
in ISO strings.

In property bags, a 'seconds: 60' property is not subject to that rule: it
should be handled according to the overflow option if there is one.

These tests existed already for some types; regularize them and add the
ones that didn't exist yet.
2022-05-03 08:18:02 +02:00
Philip Chimento 27f0104bc6 Regularize Temporal.*.from() object cloning tests
Each from() method except Calendar and TimeZone should test that when you
pass an instance of that type, the return value is a clone of that
instance, and a distinct object.

These tests existed already for some types; regularize them and add the
ones that didn't exist yet.

In order to test the referenceISODay of a PlainYearMonth we add an
argument to TemporalHelpers.assertPlainYearMonth.
2022-05-03 08:18:02 +02:00
Ms2ger b649e6b22a Temporal: Port some Duration.compare tests. 2022-04-29 10:58:05 -07:00
Ms2ger 7f2668f807 Temporal: Port a few tests for Duration#{add,subtract}. 2022-04-27 09:31:33 +02:00
Ms2ger efcac4c05a Temporal: Port some Duration tests. 2022-04-25 11:07:11 +02:00
Philip Chimento 78c6ec7f1c Test wrong types in conversions to Temporal types
These tests cover, for every API entry point where a Temporal object is
expected, what happens when a value of a different type is passed in that
can't be converted.

Most entry points can convert a string to the expected Temporal type, and
will do ToString on any non-Object argument, and throw RangeError if the
result isn't a string that's convertible to that Temporal type. ToString
will throw TypeError on a Symbol.

Most entry points also take a property bag, and will throw TypeError if
the property bag doesn't have the required properties.

We also have to test for TimeZone and Calendar what happens if the wrong
type is provided as the value of a 'timeZone' or 'calendar' property in
another property bag, up to one level of nested properties.
2022-04-21 12:14:10 -07:00
Philip Chimento afce1b3fde Test conversion of Number to Temporal objects
Adds tests for conversion of a Number whose corresponding toString() value
is a valid ISO string. For some Temporal types this is possible, with a
number like 20220418.

Especially for Temporal.Calendar, we have to take into account the case
where the number is provided as the value for the 'calendar' property in a
property bag, and the case of up to one level of nested property bag as
well.

Regularizes and expands existing tests for this case.
2022-04-21 12:14:10 -07:00
Ms2ger ff5af6fccf Temporal: Consolidate tests for invalid string argument to round(). 2022-04-15 10:12:19 -07:00
Philip Chimento 3905c0c80a Expand toString() rounding tests from PlainTime to cover other types
This takes the tests of the rounding functionality of
Temporal.PlainTime.p.toString() and adds similar tests covering the
equivalent functionality to Duration, Instant, PlainDateTime, and
ZonedDateTime: all the types that have rounding and precision controls
for how they output their subsecond values.

It also takes the opportunity to improve the existing PlainTime tests:

- fractionalseconddigits-auto.js: More descriptive variable names. Added
  assertion messages.
- fractionalseconddigits-number.js: Ditto.
- rounding-cross-midnight.js: Use constructor directly to remove coupling
  with from().
- roundingmode-*.js: Add additional tests for specifying the precision
  using fractionalSecondDigits.
- smallestunit-fractionalseconddigits.js: Add assertion messages.
2022-04-13 10:46:20 +02:00
Philip Chimento 4ac16c2589 Add tests for Temporal options bags being of the wrong type
This consolidates the few existing tests for options bags in Temporal
being of the wrong type, and adds them for every entry point in Temporal
that accepts an options bag.

These are mostly identical tests, but there is a variation for methods
like round() where either an options bag or string is accepted.
2022-04-13 10:46:20 +02:00
Philip Chimento 9b2c98c02b Bring existing "invalid string" tests for smallestUnit and largestUnit in sync
Add a consistent set of invalid strings for all of the
smallestunit-invalid-string.js and largestunit-invalid-string.js tests:
- "era" and "eraYear" in singular and plural
- all of the units that are disallowed for that particular method call, in
  singular and plural
- an allowed unit with \0 at the end
- an allowed unit with an "i" replaced by a dotless i
- an allowed unit but with all-caps
- an unrelated string.
2022-04-13 10:46:20 +02:00
Philip Chimento b4c0aeda20 Bring existing toString options tests in sync with each other
Of the toString() methods that have options for printing a time with
seconds and fractional seconds, PlainTime seems to have the most
comprehensive set of tests. Bring all the others (Duration, Instant,
PlainDateTime, and ZonedDateTime) in sync with PlainTime, and edit the
PlainTime ones where necessary to include improvements from the others.

Tests:
  - fractionalseconddigits-invalid-string.js: copy and expand on
    PlainTime's more comprehensive set of invalid strings. Add assertion
    message. Fix front matter.
  - fractionalseconddigits-non-integer.js: Fix front matter.
  - fractionalseconddigits-out-of-range.js: make sure infinity is tested.
    Add assertion messages. Fix front matter.
  - fractionalseconddigits-undefined.js: copy PlainTime's more
    comprehensive test with whole minutes, whole seconds, and subseconds.
    Copy PlainTime's test of an empty function object. Add more
    descriptive variable names and assertion messages. Fix front matter.
  - fractionalseconddigits-wrong-type.js: inline and delete TemporalHelper
    used here; it was only good for this test anyway. Improve assertion
    messages.
  - smallestunit-valid-units.js: copy PlainTime's test with a second value
    with zero seconds even. Refactor repetitive tests into a loop. Copy
    the invalid unit "era" from the Instant test. Add assertion messages.
2022-04-13 10:46:20 +02:00
Philip Chimento ac19506a01 Add tests ensuring that observable calls are made with options === undefined
Where possible, observable calls originating from within Temporal, that
require an options argument, should pass `undefined` as that options
argument, rather than `{}` or `Object.create(null)`.

See tc39/proposal-temporal#1685.
2022-04-04 16:24:17 -04:00
Jesse Alama 76b0bafba6 Update test/built-ins/Temporal/Duration/compare/twenty-five-hour-day.js
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
2022-03-29 16:50:41 -07:00
Jesse Alama 2aa754b7cf Add test for DST balancing
References:

+ https://github.com/tc39/proposal-temporal/issues/1791

Thanks @ptomato for the suggestion to use
`springForwardFallBackTimeZone`.
2022-03-29 16:50:41 -07:00
Frank Tang 0bad719e79 Add test for Temporal.Duration.p*.abs
(Philip, March 2022: This was originally Frank's PR #3062. I did some
reformatting and removed duplicate tests)
2022-03-29 11:23:43 -04:00
Frank Tang f23602f6ce Add test for Temporal.Duration.p*.negated
(Philip, March 2022: This was originally Frank's PR #3063. I did some
reformatting and removed duplicate tests)
2022-03-29 11:23:43 -04:00
Frank Tang b8af7ff369 Add test for Temporal.Duration.p*.toJSON
(Philip, March 2022: This was originally Frank's PR #3064. I did some
reformatting and removed duplicate tests)
2022-03-29 11:23:43 -04:00
Frank Tang 2c8b69f8d0 Add tests for Temporal.Duration.p*.with
(Philip, March 2022: This was originally Frank's PR #3065. I did some
reformatting, removed duplicate tests, and combined with some existing
tests.)
2022-03-29 11:23:43 -04:00
Ms2ger 104e5e8fab Test more invalid values for roundingMode. 2022-03-11 09:51:57 +01:00