forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port some basic Temporal.PlainDateTime tests from Demitasse to test262 (
tc39#3430) * Create a Temporal.PlainDateTime with all arguments supplied. Migrates some tests that currently exist in the proposal-temporal repo. * Check all data in Temporal.PlainDateTimes, variously constructed Enrich existing tests to check all basic data in the instance of `Temporal.PlainDateTime`, not just a single field. These additional checks were motivated by the migration of existing Demitasse tests in the proposal-temporal repo to test262. The Demitasse tests check more than a single field.
- Loading branch information
1 parent
f71d5e2
commit 7b78d4b
Showing
68 changed files
with
1,571 additions
and
26 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/PlainDateTime/compare/argument-object-insufficient-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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.plaindatetime.compare | ||
description: Plain object arguments may throw if they do not contain sufficient information | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789); | ||
const dt2 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => Temporal.PlainDateTime.compare({ year: 1976 }, dt2), | ||
"object must contain at least the required properties (first arg)" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => Temporal.PlainDateTime.compare(dt1, { year: 2019 }), | ||
"object must contain at least the required properties (second arg)" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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.plaindatetime.compare | ||
description: Checking a typical case (nothing undefined, no NaNs, does not throw, etc.) | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789); | ||
const dt2 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare(dt1, dt1), | ||
0, | ||
"equal" | ||
); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare(dt1, dt2), | ||
-1, | ||
"smaller/larger" | ||
); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare(dt2, dt1), | ||
1, | ||
"larger/smaller" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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.plaindatetime.compare | ||
description: Arguments may be casted (string, plain object) | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789); | ||
const dt2 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare({ year: 1976, month: 11, day: 18, hour: 15 }, dt2), | ||
-1, | ||
"casts first argument (plain object)" | ||
); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare("1976-11-18T15:23:30.123456789", dt2), | ||
-1, | ||
"casts first argument (string)" | ||
); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare(dt1, { year: 2019, month: 10, day: 29, hour: 10 }), | ||
-1, | ||
"casts second argument (plain object)" | ||
); | ||
|
||
assert.sameValue( | ||
Temporal.PlainDateTime.compare(dt1, "2019-10-29T10:46:38.271986102"), | ||
-1, | ||
"casts second argument (string)" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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.plaindatetime | ||
description: Checking an explicitly constructed instance with all arguments | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const calendar = Temporal.Calendar.from("iso8601"); | ||
const datetime = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar); | ||
|
||
TemporalHelpers.assertPlainDateTime(datetime, | ||
1976, 11, "M11", 18, 15, 23, 30, 123, 456, 789, | ||
"check instance (all arguments supplied)" | ||
); | ||
|
||
assert.sameValue( | ||
datetime.calendar, | ||
calendar, | ||
"calendar supplied in constructor can be extracted and is unchanged" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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.plaindatetime | ||
description: Testing combinations of since, until, add, subtract, and negated | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const earlier = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789); | ||
const later = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102); | ||
const units = ["years", "months", "weeks", "days", "hours", "minutes", "seconds"]; | ||
|
||
units.forEach((largestUnit) => { | ||
const diff = later.since(earlier, { largestUnit }); | ||
TemporalHelpers.assertDurationsEqual( | ||
earlier.since(later, { largestUnit }), | ||
diff.negated(), | ||
`(${earlier}).since(${later}) == (${later}).since(${earlier}).negated()` | ||
); | ||
TemporalHelpers.assertDurationsEqual( | ||
earlier.until(later, { largestUnit }), | ||
diff, | ||
`(${earlier}).until(${later}) == (${later}).since(${earlier})` | ||
); | ||
assert.sameValue( | ||
earlier.add(diff).equals(later), | ||
true, | ||
`(${earlier}).add(${diff}) == (${later})` | ||
); | ||
assert.sameValue( | ||
later.subtract(diff).equals(earlier), | ||
true, | ||
`(${later}).subtract(${diff}) == (${earlier})` | ||
); | ||
assert.sameValue( | ||
earlier.subtract(diff.negated()).equals(later), | ||
true, | ||
"symmetrical with regard to negative durations (1)" | ||
); | ||
assert.sameValue( | ||
later.add(diff.negated()).equals(earlier), | ||
true, | ||
"symmetrical with regard to negative durations (2)" | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/PlainDateTime/prototype/add/ambiguous-date.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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.plaindatetime.prototype.add | ||
description: Ambiguous addition is handled according to the overflow option | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); | ||
|
||
TemporalHelpers.assertPlainDateTime( | ||
jan31.add({ months: 1 }), | ||
2020, 2, "M02", 29, 15, 0, 0, 0, 0, 0, | ||
"constrain when ambiguous result (overflow options not supplied)" | ||
); | ||
|
||
TemporalHelpers.assertPlainDateTime( | ||
jan31.add({ months: 1 }, { overflow: "constrain" }), | ||
2020, 2, "M02", 29, 15, 0, 0, 0, 0, 0, | ||
"constrain when ambiguous result (overflow options supplied)" | ||
); | ||
|
||
assert.throws( | ||
RangeError, | ||
() => jan31.add({ months: 1 }, { overflow: "reject" }), | ||
"throw when ambiguous result with reject" | ||
); |
17 changes: 17 additions & 0 deletions
17
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-duration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.plaindatetime.prototype.add | ||
description: Duration object arguments are handled | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); | ||
|
||
TemporalHelpers.assertPlainDateTime( | ||
jan31.add(Temporal.Duration.from("P1MT1S")), | ||
2020, 2, "M02", 29, 15, 0, 1, 0, 0, 0, | ||
"Duration argument" | ||
); |
35 changes: 35 additions & 0 deletions
35
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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.plaindatetime.prototype.add | ||
description: At least one recognized property has to be present in argument | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => jan31.add({}), | ||
"empty object not acceptable" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => jan31.add({ month: 12 }), // should be "months" | ||
"misspelled property in argument throws if no other properties are present" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
() => jan31.add({ nonsense: true }), | ||
"unrecognized properties throw if no other recognized property is present" | ||
); | ||
|
||
TemporalHelpers.assertPlainDateTime( | ||
jan31.add({ nonsense: 1, days: 1 }), | ||
2020, 2, "M02", 1, 15, 0, 0, 0, 0, 0, | ||
"unrecognized properties ignored provided at least one recognized property is present" | ||
); |
18 changes: 18 additions & 0 deletions
18
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-plain-object-mixed-signs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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.plaindatetime.prototype.add | ||
description: Positive and negative values in the temporalDurationLike argument are not acceptable | ||
features: [Temporal] | ||
---*/ | ||
|
||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); | ||
|
||
["constrain", "reject"].forEach((overflow) => { | ||
assert.throws( | ||
RangeError, | ||
() => jan31.add({ hours: 1, minutes: -30 }, { overflow }), | ||
`mixed positive and negative values always throw (overflow = "${overflow}")` | ||
); | ||
}); |
Oops, something went wrong.