Commit Graph

172 Commits

Author SHA1 Message Date
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
Ms2ger 51ce1fa00f Expand some Duration#toString() tests. 2022-03-10 17:05:49 -05:00
Ms2ger c6c31c8dac Add and expand tests for Duration constructor / from(). 2022-03-10 17:05:49 -05:00
Ms2ger d45476b9fd Add a test for observable calls in Temporal.Duration constructor. 2022-03-10 17:05:49 -05:00
Jesse Alama 525313395b Add tests for with() copying defined properties of source object
https://github.com/tc39/proposal-temporal/issues/1910 found a bug in an
indentation level of a line in the Temporal proposal, which affected the
outcome of the PreparePartialTemporalFields abstract operation. This adds
tests for all entry points that use that abstract operation, to make sure
the behaviour is correct: only defined properties are copied in with()
methods.

This was a normative change that achieved consensus at the December 2021
TC39 meeting.
2022-02-08 15:43:25 -05:00
Philip Chimento 6322630064 Add Duration.toString test for fractionalSecondDigits/smallestUnit
https://github.com/tc39/proposal-temporal/pull/1956 clarified that the
fractionalSecondDigits and smallestUnit options to
Temporal.Duration.p.toString() specified the exact number of digits after
the decimal point, no more and no less.

This was a normative change that achieved consensus at the December 2021
TC39 meeting.
2022-02-08 15:43:25 -05:00
Philip Chimento 7b45a862b1 Test rounding mode in Duration strings with fractional units
https://github.com/tc39/proposal-temporal/pull/1907 was a bug that caused
negative Duration strings with fractional units to be rounded incorrectly.
Add tests that ensure the rounding mode is correct.

This was a normative change that achieved consensus at the December 2021
TC39 meeting.
2022-02-08 15:43:25 -05:00
Jesse Alama 7d82f8ac63 Add tests for invalid extended year "-000000"
https://github.com/tc39/proposal-temporal/issues/1753 records the
consensus reached at the October 2021 TC39 meeting to disallow "-000000"
as an extended year, both in Date.parse and Temporal. This adds tests for
the Temporal part of that.
2022-02-01 17:59:02 -05:00
Jesse Alama 7835f64ae0 Check relativeTo for certain non-zero years, weeks, months, and days
https://github.com/tc39/proposal-temporal/pull/1780 fixed a typo in the
UnbalanceDurationRelative abstract operation, which should affect the
entry points tested here.

This was a normative change that achieved consensus at the October 2021
TC39 meeting.
2022-02-01 17:59:02 -05:00
Philip Chimento 17b3c567ff Add more variations of ISO strings to "timezone-string-datetime" tests
Some of these tests have a larger variation of valid ISO strings that they
test, and others don't. Use the larger variation across all of these
files.
2022-01-19 13:47:43 -05:00
Philip Chimento ff62561247 Ensure tests in main suite do not use Intl time zones
This requires a few adjustments of time zone names and offsets in some
places. The only named time zone that is required to be supported by an
implementation not supporting ECMA-402 is "UTC".
2022-01-19 13:47:43 -05:00
Philip Chimento 6058710478 Improve various assertion messages 2022-01-19 13:47:43 -05:00
Jesse Alama 85973b35e4 Rendering Duration with negative components
A rendered Duration that was constructed with negative
componented begins with a `-`, but that's the last
time a minus sign appears.
2021-12-14 13:39:19 -05:00
Philip Chimento 8d025ef1d6 Test that non-undefined, non-zoned relativeTo parameters are converted to PlainDate
Tests for the normative changes made to Temporal in
https://github.com/tc39/proposal-temporal/pull/1873

This adds a new Temporal helper calendar that asserts that its dateAdd()
method is always called with a PlainDate instance. This allows testing
that relativeTo parameters are always converted to PlainDate if they are
not ZonedDateTime and not undefined. Prior to the normative PR, they
would be converted to PlainDateTime instead.

Additionally and optionally, the helper calendar can also assert that its
dateAdd() method is called with a specific PlainDate instance. This allows
testing that the instance is the same PlainDate passed as the relativeTo
parameter (in the case of Duration methods) or is the receiver (in the
case of PlainDate methods). For the PlainDateTime and PlainYearMonth
methods the PlainDate instance is synthesized internally so there is no
need to assert that dateAdd() is called with a specific instance.
2021-12-14 13:39:19 -05:00
Justin Grant 6c2884eb9e Verify that `Temporal.*.prototype` isn't writeable 2021-12-14 13:38:14 -05:00
Philip Chimento 1d09acaac1 Fix not-callable getOffsetNansecondsFor tests
Unfortunately, in #3304 I made a last-minute mistake when I added the
uncallable value to the assertion message, and neglected to test it;
Symbols can't be converted to strings like that, so these tests would
fail. This fixes the assertion messages.
2021-11-30 14:36:59 -05:00
Philip Chimento cba42e88c7 Tests for string shorthand API in round() and total()
Tests for the normative changes made to Temporal in
https://github.com/tc39/proposal-temporal/pull/1875

For convenience, adds some functions to TemporalHelpers to assert that two
Temporal objects are equal, for Duration, Instant, PlainDateTime,
PlainTime, and ZonedDateTime.
2021-11-16 17:06:06 -05:00
Philip Chimento ae53326189 Test TypeError is thrown when getOffsetNanosecondsFor is not callable
Tests for the normative changes made to Temporal in
https://github.com/tc39/proposal-temporal/pull/1829
In a previous version of the specification, there was a fallback to the
intrinsic getOffsetNanosecondsFor when it was undefined.
2021-11-16 17:06:06 -05:00
Sarah GHP 171d4382de Add tests for RangeErrors on fractional inputs to Duration constructor 2021-11-16 17:06:06 -05:00
Philip Chimento 3dbf940c9b Test removal of sub-minute time zone offsets in ISO strings
Tests for the normative changes made to Temporal in
https://github.com/tc39/proposal-temporal/pull/1871
2021-11-01 14:07:02 -04:00
Philip Chimento 4158545044 Temporal.PlainTime property bags
Tests for the normative change to Temporal made in
https://github.com/tc39/proposal-temporal/pull/1862
2021-11-01 14:07:02 -04:00
Philip Chimento 77a34cf93f Add Temporal tests
This copies over the tests that previously existed in the
tc39/proposal-temporal repository.

For context, see thread starting at:
https://github.com/tc39/test262/issues/3002#issuecomment-926234480

In service of https://github.com/tc39/test262/issues/3002
2021-10-01 14:30:12 -04:00
Philip Chimento 45a913c057
Add branding tests from Temporal (#3138)
Closes: #3137

Co-authored-by: Ms2ger <Ms2ger@igalia.com>
2021-08-11 12:31:23 -07:00