mirror of https://github.com/tc39/test262.git
Temporal: Move all tests out of ZonedDateTime/old/with.js under staging into separate files under test/built-ins (#4297)
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
This commit is contained in:
parent
0f6b269400
commit
8cc0560713
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: with() works on various values.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
|
||||
|
||||
// zdt.with({ year: 2019 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ year: 2019 }),
|
||||
Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ month: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ month: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-05-18T15:23:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ monthCode: "M05" }) works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ monthCode: "M05" }),
|
||||
Temporal.ZonedDateTime.from("1976-05-18T15:23:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ day: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ day: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-05T15:23:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ hour: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ hour: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T05:23:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ minute: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ minute: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:05:30.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ second: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ second: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:23:05.123456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ millisecond: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ millisecond: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:23:30.005456789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ microsecond: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ microsecond: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123005789+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ nanosecond: 5 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ nanosecond: 5 }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456005+00:00[UTC]"));
|
||||
|
||||
// zdt.with({ month: 5, second: 15 } works
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({
|
||||
month: 5,
|
||||
second: 15
|
||||
}),
|
||||
Temporal.ZonedDateTime.from("1976-05-18T15:23:15.123456789+00:00[UTC]"));
|
18
test/built-ins/Temporal/ZonedDateTime/prototype/with/incorrectly-spelled-properties-ignored.js
vendored
Normal file
18
test/built-ins/Temporal/ZonedDateTime/prototype/with/incorrectly-spelled-properties-ignored.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Incorrectly-spelled properties are ignored.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({
|
||||
month: 12,
|
||||
days: 15
|
||||
}),
|
||||
Temporal.ZonedDateTime.from("1976-12-18T15:23:30.123456789+00:00[UTC]"));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/invalid-disambiguation.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/invalid-disambiguation.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Invalid disambiguation.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
[
|
||||
"",
|
||||
"EARLIER",
|
||||
"balance"
|
||||
].forEach(disambiguation => assert.throws(RangeError, () => zdt.with({ day: 5 }, { disambiguation })));
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Invalid disambiguation.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
[
|
||||
"",
|
||||
"PREFER",
|
||||
"balance"
|
||||
].forEach(offset => assert.throws(RangeError, () => zdt.with({ day: 5 }, { offset })));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/month-and-month-code-must-agree.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/month-and-month-code-must-agree.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: month and monthCode must agree.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
// month and monthCode must agree
|
||||
assert.throws(RangeError, () => zdt.with({
|
||||
month: 5,
|
||||
monthCode: "M06"
|
||||
}));
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Object argument must contain at least one correctly-spelled property.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
assert.throws(TypeError, () => zdt.with({}));
|
||||
assert.throws(TypeError, () => zdt.with({ months: 12 }));
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Overflow options work.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
|
||||
|
||||
const overflow = "constrain";
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ month: 29 }, { overflow }),
|
||||
Temporal.ZonedDateTime.from("1976-12-18T15:23:30.123456789+00:00[UTC]"));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ day: 31 }, { overflow }),
|
||||
Temporal.ZonedDateTime.from("1976-11-30T15:23:30.123456789+00:00[UTC]"));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ hour: 29 }, { overflow }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T23:23:30.123456789+00:00[UTC]"));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
zdt.with({ nanosecond: 9000 }, { overflow }),
|
||||
Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456999+00:00[UTC]"));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/overflow-reject-throws.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/overflow-reject-throws.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Overflow option reject works properly.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
|
||||
|
||||
const overflow = "reject";
|
||||
assert.throws(RangeError, () => zdt.with({ month: 29 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ day: 31 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ hour: 29 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ nanosecond: 9000 }, { overflow }));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-if-calendar-name-included.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-if-calendar-name-included.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Throws if given a property bag with a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
// throws if calendarName is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
calendar: "iso8601"
|
||||
}));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-if-timezone-included.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-if-timezone-included.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Throws if timeZone is included.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
// throws if timeZone is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
timeZone: "UTC"
|
||||
}));
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Throws if given a string.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
assert.throws(TypeError, () => zdt.with("1976-11-18T12:00+00:00[UTC]"));
|
||||
assert.throws(TypeError, () => zdt.with("1976-11-18"));
|
||||
assert.throws(TypeError, () => zdt.with("12:00"));
|
||||
assert.throws(TypeError, () => zdt.with("invalid"));
|
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-on-temporal-object-with-calendar.js
vendored
Normal file
16
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-on-temporal-object-with-calendar.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Throws if given a Temporal object with a calendar.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
assert.throws(TypeError, () => zdt.with(new Temporal.PlainDateTime(1976, 11, 18, 12, 0)));
|
||||
assert.throws(TypeError, () => zdt.with(new Temporal.PlainDate(1976, 11, 18)));
|
||||
assert.throws(TypeError, () => zdt.with(new Temporal.PlainTime(12, 0)));
|
||||
assert.throws(TypeError, () => zdt.with(new Temporal.PlainYearMonth(1976, 11)));
|
||||
assert.throws(TypeError, () => zdt.with(new Temporal.PlainMonthDay(11, 18)));
|
12
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-on-temporal-object-with-time-zone.js
vendored
Normal file
12
test/built-ins/Temporal/ZonedDateTime/prototype/with/throws-on-temporal-object-with-time-zone.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Throws if given a Temporal.ZonedDateTime with a time zone
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
assert.throws(TypeError, () => zdt.with(zdt));
|
|
@ -1,120 +0,0 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: Temporal.ZonedDateTime.prototype.with()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var zdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789).toZonedDateTime("UTC");
|
||||
|
||||
// zdt.with({ year: 2019 } works
|
||||
assert.sameValue(`${ zdt.with({ year: 2019 }) }`, "2019-11-18T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ month: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ month: 5 }) }`, "1976-05-18T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ monthCode: "M05" }) works
|
||||
assert.sameValue(`${ zdt.with({ monthCode: "M05" }) }`, "1976-05-18T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// month and monthCode must agree
|
||||
assert.throws(RangeError, () => zdt.with({
|
||||
month: 5,
|
||||
monthCode: "M06"
|
||||
}));
|
||||
|
||||
// zdt.with({ day: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ day: 5 }) }`, "1976-11-05T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ hour: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ hour: 5 }) }`, "1976-11-18T05:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ minute: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ minute: 5 }) }`, "1976-11-18T15:05:30.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ second: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ second: 5 }) }`, "1976-11-18T15:23:05.123456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ millisecond: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ millisecond: 5 }) }`, "1976-11-18T15:23:30.005456789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ microsecond: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ microsecond: 5 }) }`, "1976-11-18T15:23:30.123005789+00:00[UTC]");
|
||||
|
||||
// zdt.with({ nanosecond: 5 } works
|
||||
assert.sameValue(`${ zdt.with({ nanosecond: 5 }) }`, "1976-11-18T15:23:30.123456005+00:00[UTC]");
|
||||
|
||||
// zdt.with({ month: 5, second: 15 } works
|
||||
assert.sameValue(`${ zdt.with({
|
||||
month: 5,
|
||||
second: 15
|
||||
}) }`, "1976-05-18T15:23:15.123456789+00:00[UTC]");
|
||||
|
||||
// Overflow options
|
||||
// constrain
|
||||
var overflow = "constrain";
|
||||
assert.sameValue(`${ zdt.with({ month: 29 }, { overflow }) }`, "1976-12-18T15:23:30.123456789+00:00[UTC]");
|
||||
assert.sameValue(`${ zdt.with({ day: 31 }, { overflow }) }`, "1976-11-30T15:23:30.123456789+00:00[UTC]");
|
||||
assert.sameValue(`${ zdt.with({ hour: 29 }, { overflow }) }`, "1976-11-18T23:23:30.123456789+00:00[UTC]");
|
||||
assert.sameValue(`${ zdt.with({ nanosecond: 9000 }, { overflow }) }`, "1976-11-18T15:23:30.123456999+00:00[UTC]");
|
||||
|
||||
// reject
|
||||
var overflow = "reject";
|
||||
assert.throws(RangeError, () => zdt.with({ month: 29 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ day: 31 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ hour: 29 }, { overflow }));
|
||||
assert.throws(RangeError, () => zdt.with({ nanosecond: 9000 }, { overflow }));
|
||||
|
||||
// invalid disambiguation
|
||||
[
|
||||
"",
|
||||
"EARLIER",
|
||||
"balance"
|
||||
].forEach(disambiguation => assert.throws(RangeError, () => zdt.with({ day: 5 }, { disambiguation })));
|
||||
|
||||
// invalid offset
|
||||
[
|
||||
"",
|
||||
"PREFER",
|
||||
"balance"
|
||||
].forEach(offset => assert.throws(RangeError, () => zdt.with({ day: 5 }, { offset })));
|
||||
|
||||
// object must contain at least one correctly-spelled property
|
||||
assert.throws(TypeError, () => zdt.with({}));
|
||||
assert.throws(TypeError, () => zdt.with({ months: 12 }));
|
||||
|
||||
// incorrectly-spelled properties are ignored
|
||||
assert.sameValue(`${ zdt.with({
|
||||
month: 12,
|
||||
days: 15
|
||||
}) }`, "1976-12-18T15:23:30.123456789+00:00[UTC]");
|
||||
|
||||
// throws if timeZone is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
timeZone: "UTC"
|
||||
}));
|
||||
|
||||
// throws if given a Temporal object with a time zone
|
||||
assert.throws(TypeError, () => zdt.with(zdt));
|
||||
|
||||
// throws if calendarName is included
|
||||
assert.throws(TypeError, () => zdt.with({
|
||||
month: 2,
|
||||
calendar: "iso8601"
|
||||
}));
|
||||
|
||||
// throws if given a Temporal object with a calendar
|
||||
assert.throws(TypeError, () => zdt.with(Temporal.PlainDateTime.from("1976-11-18T12:00")));
|
||||
assert.throws(TypeError, () => zdt.with(Temporal.PlainDate.from("1976-11-18")));
|
||||
assert.throws(TypeError, () => zdt.with(Temporal.PlainTime.from("12:00")));
|
||||
assert.throws(TypeError, () => zdt.with(Temporal.PlainYearMonth.from("1976-11")));
|
||||
assert.throws(TypeError, () => zdt.with(Temporal.PlainMonthDay.from("11-18")));
|
||||
|
||||
// throws if given a string
|
||||
assert.throws(TypeError, () => zdt.with("1976-11-18T12:00+00:00[UTC]"));
|
||||
assert.throws(TypeError, () => zdt.with("1976-11-18"));
|
||||
assert.throws(TypeError, () => zdt.with("12:00"));
|
||||
assert.throws(TypeError, () => zdt.with("invalid"));
|
||||
|
Loading…
Reference in New Issue