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.
Temporal: Tests for PlainDateTime exposed in DisambiguatePossibleInst…
…ants In the AO DisambiguatePossibleInstants, a PlainDateTime instance is passed to user code. This instance should have the built-in ISO 8601 calendar. Here are some tests that ensure it does. See tc39/proposal-temporal#2671.
- Loading branch information
Showing
20 changed files
with
1,114 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...ion/compare/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.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,55 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.compare | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; | ||
|
||
Temporal.Duration.compare(new Temporal.Duration(1), new Temporal.Duration(2), { relativeTo }); | ||
|
||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); |
56 changes: 56 additions & 0 deletions
56
...ototype/add/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.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,56 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.add | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 1); | ||
instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); | ||
|
||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); |
56 changes: 56 additions & 0 deletions
56
...otype/round/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.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,56 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 0, 24); | ||
instance.round({ largestUnit: "years", relativeTo }); | ||
|
||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); |
56 changes: 56 additions & 0 deletions
56
...pe/subtract/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.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,56 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.subtract | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 1); | ||
instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); | ||
|
||
assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); |
56 changes: 56 additions & 0 deletions
56
...otype/total/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.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,56 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.total | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 0, 24); | ||
instance.total({ unit: "days", relativeTo }); | ||
|
||
assert.sameValue(timeZone.calls, 10, "getPossibleInstantsFor should have been called 10 times"); |
55 changes: 55 additions & 0 deletions
55
...lainDate/prototype/toZonedDateTime/getpossibleinstantsfor-called-with-iso8601-calendar.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,55 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.tozoneddatetime | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, nonBuiltinISOCalendar); | ||
instance.toZonedDateTime(timeZone); | ||
|
||
assert.sameValue(timeZone.calls, 2, "getPossibleInstantsFor should have been called 2 times"); |
55 changes: 55 additions & 0 deletions
55
...DateTime/prototype/toZonedDateTime/getpossibleinstantsfor-called-with-iso8601-calendar.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,55 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime | ||
description: > | ||
Time zone's getPossibleInstantsFor is called with a PlainDateTime with the | ||
built-in ISO 8601 calendar | ||
features: [Temporal] | ||
info: | | ||
DisambiguatePossibleInstants: | ||
2. Let _n_ be _possibleInstants_'s length. | ||
... | ||
5. Assert: _n_ = 0. | ||
... | ||
19. If _disambiguation_ is *"earlier"*, then | ||
... | ||
c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). | ||
... | ||
20. Assert: _disambiguation_ is *"compatible"* or *"later"*. | ||
... | ||
23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). | ||
24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). | ||
---*/ | ||
|
||
class SkippedDateTime extends Temporal.TimeZone { | ||
constructor() { | ||
super("UTC"); | ||
this.calls = 0; | ||
} | ||
|
||
getPossibleInstantsFor(dateTime) { | ||
// Calls occur in pairs. For the first one return no possible instants so | ||
// that DisambiguatePossibleInstants will call it again | ||
if (this.calls++ % 2 == 0) { | ||
return []; | ||
} | ||
|
||
assert.sameValue( | ||
dateTime.getISOFields().calendar, | ||
"iso8601", | ||
"getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" | ||
); | ||
return super.getPossibleInstantsFor(dateTime); | ||
} | ||
} | ||
|
||
const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); | ||
const timeZone = new SkippedDateTime(); | ||
|
||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 0, nonBuiltinISOCalendar); | ||
instance.toZonedDateTime(timeZone); | ||
|
||
assert.sameValue(timeZone.calls, 2, "getPossibleInstantsFor should have been called 2 times"); |
Oops, something went wrong.