Commit Graph

57 Commits

Author SHA1 Message Date
André Bargull 57b9f154a6 Allow alternative implementations for Chinese lunar calendar 2024-05-29 10:47:09 +02:00
André Bargull efe0b1871f Split yearMonthFromFields/reference-day.js into calendar specific files 2024-05-29 10:47:09 +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 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 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
Aditi 0fd1675f7e Temporal: Add weekOfYear() and yearOfWeek() tests for custom calendars 2024-02-21 10:40:18 -08:00
Aditi ae8fe25b5a Temporal: Tests for week-numbering algorithm 2024-02-21 10:40:18 -08:00
Philip Chimento f4377a7cf0 Temporal: Fix test to check for TypeError with only one of era/eraYear
These tests were incorrect, in checking for a RangeError when only one of
the era/eraYear fields were given. From CalendarResolveFields:

"The operation throws a *TypeError* exception if the properties of
_fields_ are internally inconsistent within the calendar or insufficient
to identify a unique instance of _type_ in the calendar."
2023-10-26 12:37:43 -04:00
Philip Chimento dab8ccc5df Temporal: Add more coverage for non-ISO PlainMonthDay underspecification
Built-in non-ISO calendars require either monthCode/day, or month/day plus
some form of year specification.

This adds test coverage for each of the categories listed in
https://github.com/tc39/proposal-temporal/issues/2664, of which some must
currently reside in the test/intl402/ folders.
2023-10-26 12:37:43 -04: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
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
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 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
Justin Grant daefac0814 Add test to validate fix to proposal-temporal#2537
The Temporal polyfill had a math bug in Calendar.p.dateUntil where
non-ISO calendars would unexpectedly throw when calculating
the number of years between two dates where the year were different,
the month codes were different, but the months were the same because
the earlier date's month was after a leap month.

This test validates the fix to this bug.
2023-04-03 17:27:34 -07:00
Justin Grant aed56d9fa6 Add test to validate fix to proposal-temporal#2383
The Temporal polyfill had an infinite loop for non-ISO calendars
when Calendar.p.dateUntil was called to calculate the duration
between two identical dates. This test validates that PT0S is returned
in that case.
2023-04-03 17:27:34 -07:00
Aditi 53e5ef817e Add Temporal era/eraYear tests 2023-03-07 16:00:10 -08:00
Richard Gibson 4f5eb40ee0 Temporal: Test updates for mergeFields output property order
Normative PR: https://github.com/tc39/proposal-temporal/pull/2505
2023-03-06 14:30:35 -08:00
Philip Chimento 76a14bf659 Temporal: Tests for reference ISO dates
Tests for the process of calculating the reference ISO day for
Temporal.PlainYearMonth and the reference ISO year for
Temporal.PlainMonthDay.

Normative PR: https://github.com/tc39/proposal-temporal/pull/2475
2023-02-17 09:56:13 +01:00
Philip Chimento a29788dd5d Temporal: Tests for calendar-specific mergeFields
In https://github.com/tc39/proposal-temporal/pull/2474, which achieved
consensus at the TC39 plenary meeting of 2023-01-31, the implementation-
defined steps for Temporal.Calendar.prototype.mergeFields had their
language tightened, to better specify what implementations must do.

This adds tests covering the new spec language, and moves one related test
out of staging.
2023-02-16 12:00:30 -08:00
Aditi 1c47728a20 Remove failing tests for CalendarFields and CalendarMergeFields 2023-02-10 17:43:47 -08:00
Philip Chimento 374aac475d Regularize "calendar-case-insensitive" tests
For each entry point where a string calendar name is accepted, we should
have a test that ensures the calendar name is case-insensitive. These
tests existed but several were incomplete as they didn't take nested
properties into account, and several entry points were missing this test.

Fix a minor copy-paste issue with double semicolons.
2023-02-01 10:50:12 +01:00
Philip Chimento 6e4f412d65 Temporal: Tests for normative changes around date-only strings
As per the discussion in
https://github.com/tc39/proposal-temporal/issues/2379#issuecomment-1248557100
and the PR https://github.com/tc39/proposal-temporal/pull/2398, which is
to be presented for consensus to TC39 in the upcoming plenary meeting, UTC
offsets and the Z designator should be disallowed after any date-only
strings (YYYY-MM-DD, YYYY-MM, and MM-DD). They should only be allowed to
follow a time component. Z remains disallowed in any string being parsed
into a Plain type.

Annotations become allowed after any ISO string, even YYYY-MM and MM-DD
where they were previously disallowed.
2022-11-30 10:11:10 -08:00
Philip Chimento 3775b4774b Temporal: Add tests for new yearOfWeek API
To be presented for consensus in the November/December TC39 meeting. This
adds tests for a 'yearOfWeek' getter to PlainDate, PlainDateTime, and
ZonedDateTime, for use alongside 'weekOfYear', and tests for a
corresponding method to Calendar.

The tests are basically the existing tests of 'weekOfYear' adapted.

Temporal issue: https://github.com/tc39/proposal-temporal/issues/2405
2022-11-30 10:06:53 -08:00
Philip Chimento 34805283d9 Temporal: Add tests for fast path in ToTemporalCalendar
Normally, a plain object passed into an API that takes a Temporal.Calendar
has its 'calendar' 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.Calendar
internal slots.

This adds tests to all entry points that pass a user-supplied object to
ToTemporalCalendar, with a "poisoned" calendar object which has the
correct internal slots but a 'calendar' 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 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 6bfb4441d3 Temporal: Add tests for multiple time zone annotations
See https://github.com/tc39/proposal-temporal/pull/2397
Adds tests for ISO strings with more than one time zone annotation. These
are not syntactically correct according to the grammar and should be
rejected.
2022-10-11 12:19:49 +02:00
Philip Chimento 705cf94429 Temporal: Add tests for unknown annotation with critical flag
See https://github.com/tc39/proposal-temporal/pull/2397
Adds tests for ISO strings with unrecognized annotations with the critical
flag. These strings should all be rejected.
2022-10-11 12:19:49 +02:00
Philip Chimento dc11e501d6 Temporal: Add tests for unknown annotation without critical flag
See https://github.com/tc39/proposal-temporal/pull/2397
Adds tests for ISO strings with unrecognized annotations, (i.e., neither
time zone nor calendar), in various combinations with recognized
annotations.
2022-10-11 12:19:49 +02:00
Philip Chimento 9d87845bb0 Temporal: Add tests for calendar annotation with critical flag
See https://github.com/tc39/proposal-temporal/pull/2397
Adds tests for ISO strings with calendar annotations, with and without the
critical flag, and also a check that the second calendar annotation is
disregarded, as per the IETF draft.
2022-10-11 12:19:49 +02:00
Philip Chimento 2d015b700a Temporal: Add tests for time zone annotation with critical flag
See https://github.com/tc39/proposal-temporal/pull/2397
Adds tests for ISO strings with named and numeric offset time zone
annotations, with and without the critical flag, with various combinations
of Z and offset in front of the annotation.
2022-10-11 12:19:49 +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 31ad95d34e Temporal: Add more getOffsetNanosecondsFor validation tests
This adds tests that validate a user-callable getOffsetNanosecondsFor to
several APIs that didn't test this yet: ZonedDateTime.since/until, and
Calendar.era/eraYear.
2022-09-16 13:41:08 +02:00
Philip Chimento ce2061eccd Temporal: Adjust order of operations in Calendar.___fromFields
This implements the normative change in
https://github.com/tc39/proposal-temporal/pull/2377 which reached
consensus at the September 2022 TC39 meeting.

It changes the order in which observable operations are performed on the
values passed to the ___fromFields methods of Calendar.
2022-09-15 11:04:37 +02:00
Philip Chimento e391176717 Apply suggestions from code review 2022-09-13 11:32:16 -07:00
Aditi c6b62110f9 Added intl tests for timezone and calendar case insensitivity 2022-09-13 11:32:16 -07:00
Aditi cf51de578f Add calendar case insensitive tests 2022-09-13 11:32:16 -07:00
Philip Chimento 6685c6c81c Temporal: Add tests for casting a calendar ID string to a Temporal.Calendar
This adds tests to every entry point where a Temporal.Calendar is
accepted, making sure that a calendar ID string is also accepted.
2022-08-01 13:48:11 -07: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
Philip Chimento 0e86baf6f3
Temporal: Add tests for order of observable operations in *FromFields methods (#3568)
This adds tests for https://github.com/tc39/proposal-temporal/pull/2203
which was a normative change that reached consensus in the June 2022 TC39
plenary meeting.

Co-authored-by: Ms2ger <Ms2ger@gmail.com>
2022-06-14 15:46:16 +02:00
Ms2ger 53d6cd6d46 Temporal: Add tests for converting a ZonedDateTime to a PlainDate. 2022-06-02 08:50:05 +02:00
Philip Chimento 579268ab79 Temporal: Add tests for variant time separators
ISO strings may separate the time from the date with a case-insensitive T,
or a space. This adds tests to all entry points that take ISO strings, to
ensure that they accept an uppercase T, lowercase T, or space as the time
separator.

These tests are based on the one test for Temporal.PlainDateTime.from that
was already present.
2022-05-23 11:47:56 +02: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
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 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
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