From a93fe76f52c59086a3652b893026efde81fbf336 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Oct 2024 13:50:50 -0700 Subject: [PATCH] Temporal: Move ZonedDateTime property bag tests out of staging --- .../from/argument-propertybag-empty-throws.js | 11 ++ .../argument-propertybag-function-object.js | 20 +++ ...ropertybag-ignores-incorrect-properties.js | 21 +++ ...ument-propertybag-invalid-offset-string.js | 7 +- .../argument-propertybag-monthcode-month.js | 37 +++++ ...tybag-offset-not-agreeing-with-timezone.js | 1 + ...g-required-correctly-spelled-properties.js | 16 ++ ...pertybag-required-prop-undefined-throws.js | 18 +++ .../from/disambiguation-invalid-string.js | 11 +- .../offset-does-not-match-iana-time-zone.js | 20 +++ .../ZonedDateTime/from/overflow-options.js | 27 ++++ .../ZonedDateTime/old/property-bags.js | 142 ------------------ 12 files changed, 186 insertions(+), 145 deletions(-) create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-empty-throws.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-function-object.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-ignores-incorrect-properties.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-monthcode-month.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-correctly-spelled-properties.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-prop-undefined-throws.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/overflow-options.js delete mode 100644 test/staging/Temporal/ZonedDateTime/old/property-bags.js diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-empty-throws.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-empty-throws.js new file mode 100644 index 0000000000..b661d71650 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-empty-throws.js @@ -0,0 +1,11 @@ +// 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.zoneddatetime.from +description: Temporal.ZonedDateTime.from({}) throws. +features: [Temporal] +---*/ + +// Temporal.ZonedDateTime.from({}) throws +assert.throws(TypeError, () => Temporal.ZonedDateTime.from({})) diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-function-object.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-function-object.js new file mode 100644 index 0000000000..8037979314 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-function-object.js @@ -0,0 +1,20 @@ +// 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.zoneddatetime.from +description: Options may be a function object. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +// "1976-11-18T00:00:00+01:00[+01:00]" +const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00"); + +TemporalHelpers.assertZonedDateTimesEqual( Temporal.ZonedDateTime.from({ + year: 1976, + month: 11, + day: 18, + timeZone: "+01:00" +}, () => { +}), expected); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-ignores-incorrect-properties.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-ignores-incorrect-properties.js new file mode 100644 index 0000000000..aa3e9a3677 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-ignores-incorrect-properties.js @@ -0,0 +1,21 @@ +// 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.zoneddatetime.from +description: Incorrectly-spelled properties are ignored. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +// "1976-11-18T00:00:00+01:00[+01:00]" +const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00"); + +// can be constructed with monthCode and without month +TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({ + year: 1976, + month: 11, + day: 18, + timeZone: "+01:00", + hours: 12 +}), expected); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js index 9603bda486..964c7916b3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js @@ -19,14 +19,17 @@ const badOffsets = [ null, // must be a string true, // must be a string 1000n, // must be a string + {}, // must be a string + Symbol() // must be a string ]; offsetOptions.forEach((offsetOption) => { badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; assert.throws( - typeof(offset) === 'string' ? RangeError : TypeError, + typeof(offset) === 'string' || (typeof offset === "object" && offset !== null) ? RangeError : TypeError, () => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }), - `"${offset} is not a valid offset string (with offset option ${offsetOption})` + typeof(offset) === 'symbol' ? "symbol is not a valid offset string" + : `"${offset} is not a valid offset string (with offset option ${offsetOption})` ); }); }); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-monthcode-month.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-monthcode-month.js new file mode 100644 index 0000000000..700676ba18 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-monthcode-month.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.from +description: ZonedDateTime can be constructed with monthCode or month; must agree. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +// "1976-11-18T00:00:00+01:00[+01:00]" +const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00"); + +// can be constructed with monthCode and without month +TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({ + year: 1976, + monthCode: "M11", + day: 18, + timeZone: "+01:00" +}), expected); + +// can be constructed with month and without monthCode +TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({ + year: 1976, + month: 11, + day: 18, + timeZone: "+01:00" +}), expected) + +// month and monthCode must agree +assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ + year: 1976, + month: 11, + monthCode: "M12", + day: 18, + timeZone: "+01:00" +})); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-offset-not-agreeing-with-timezone.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-offset-not-agreeing-with-timezone.js index 4f82b9a08a..a551dd378c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-offset-not-agreeing-with-timezone.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-offset-not-agreeing-with-timezone.js @@ -11,3 +11,4 @@ const timeZone = "+01:00"; const properties = { year: 2021, month: 10, day: 28, offset: "-07:00", timeZone }; assert.throws(RangeError, () => Temporal.ZonedDateTime.from(properties), "offset property not matching time zone is rejected"); +assert.throws(RangeError, () => Temporal.ZonedDateTime.from(properties, { offset: "reject" }), "offset property not matching time zone is rejected"); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-correctly-spelled-properties.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-correctly-spelled-properties.js new file mode 100644 index 0000000000..033b77b69b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-correctly-spelled-properties.js @@ -0,0 +1,16 @@ +// 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.zoneddatetime.from +description: Options must contain at least the required correctly-spelled properties. +features: [Temporal] +---*/ + +// object must contain at least the required correctly-spelled properties +assert.throws(TypeError, () => Temporal.ZonedDateTime.from({ + years: 1976, + months: 11, + days: 18, + timeZone: "+01:00" +})); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-prop-undefined-throws.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-prop-undefined-throws.js new file mode 100644 index 0000000000..794c16db59 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-required-prop-undefined-throws.js @@ -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.zoneddatetime.from +description: Temporal.ZonedDateTime.from({}) throws. +features: [Temporal] +---*/ + +// Temporal.ZonedDateTime.from(required prop undefined) throws +assert.throws(TypeError, () => Temporal.ZonedDateTime.from({ + year: 1976, + month: undefined, + monthCode: undefined, + day: 18, + timeZone: "+01:00" +})); + diff --git a/test/built-ins/Temporal/ZonedDateTime/from/disambiguation-invalid-string.js b/test/built-ins/Temporal/ZonedDateTime/from/disambiguation-invalid-string.js index 31eefbda2e..494ee0f376 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/disambiguation-invalid-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/disambiguation-invalid-string.js @@ -25,4 +25,13 @@ const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC"); assert.throws(RangeError, () => Temporal.ZonedDateTime.from(datetime, { disambiguation: "other string" })); const propertyBag = { timeZone: "UTC", year: 2001, month: 9, day: 9, hour: 1, minute: 46, second: 40, millisecond: 987, microsecond: 654, nanosecond: 321 }; -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(propertyBag, { disambiguation: "other string" })); +[ + "", + "EARLIER", + "balance", + "other string", + 3, + null +].forEach(disambiguation => { + assert.throws(RangeError, () => Temporal.ZonedDateTime.from(propertyBag, { disambiguation })) +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js b/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js new file mode 100644 index 0000000000..6b3e34fbdc --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js @@ -0,0 +1,20 @@ +// 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.zoneddatetime.from +description: With offset 'reject', throws if offset does not match IANA time zone +features: [Temporal] +---*/ + +const obj = { + year: 2020, + month: 3, + day: 8, + hour: 1, + offset: "-04:00", + timeZone: "UTC" +}; + +assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj)); +assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" })); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/overflow-options.js b/test/built-ins/Temporal/ZonedDateTime/from/overflow-options.js new file mode 100644 index 0000000000..02fc4a6750 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/overflow-options.js @@ -0,0 +1,27 @@ +// 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.zoneddatetime.from +description: Overflow options. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const bad = { + year: 2019, + month: 1, + day: 32, + timeZone: "+01:00" +}; +// "2019-01-31T00:00:00+01:00[+01:00]" +const expected = new Temporal.ZonedDateTime(1548889200000000000n, "+01:00"); + + +assert.throws(RangeError, () => Temporal.ZonedDateTime.from(bad, { overflow: "reject" })); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from(bad), + expected); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }), + expected); diff --git a/test/staging/Temporal/ZonedDateTime/old/property-bags.js b/test/staging/Temporal/ZonedDateTime/old/property-bags.js deleted file mode 100644 index 9797623490..0000000000 --- a/test/staging/Temporal/ZonedDateTime/old/property-bags.js +++ /dev/null @@ -1,142 +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: property bags -features: [Temporal] ----*/ - -// can be constructed with monthCode and without month -assert.sameValue(`${ Temporal.ZonedDateTime.from({ - year: 1976, - monthCode: "M11", - day: 18, - timeZone: "+01:00" -}) }`, "1976-11-18T00:00:00+01:00[+01:00]"); - -// can be constructed with month and without monthCode -assert.sameValue(`${ Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - day: 18, - timeZone: "+01:00" -}) }`, "1976-11-18T00:00:00+01:00[+01:00]"); - -// month and monthCode must agree -assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - monthCode: "M12", - day: 18, - timeZone: "+01:00" -})); - -// Temporal.ZonedDateTime.from({}) throws -assert.throws(TypeError, () => Temporal.ZonedDateTime.from({})) - -// Temporal.ZonedDateTime.from(required prop undefined) throws -assert.throws(TypeError, () => Temporal.ZonedDateTime.from({ - year: 1976, - month: undefined, - monthCode: undefined, - day: 18, - timeZone: "+01:00" -})) - -// options may be a function object -assert.sameValue(`${ Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - day: 18, - timeZone: "+01:00" -}, () => { -}) }`, "1976-11-18T00:00:00+01:00[+01:00]"); - -// object must contain at least the required correctly-spelled properties -assert.throws(TypeError, () => Temporal.ZonedDateTime.from({ - years: 1976, - months: 11, - days: 18, - timeZone: "+01:00" -})); - -// incorrectly-spelled properties are ignored -assert.sameValue(`${ Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - day: 18, - timeZone: "+01:00", - hours: 12 -}) }`, "1976-11-18T00:00:00+01:00[+01:00]"); - -// does not accept non-string offset property -[ - null, - true, - 1000, - 1000n, - Symbol(), - {} -].forEach(offset => { - assert.throws( - typeof offset === "string" || (typeof offset === "object" && offset !== null) || typeof offset === "function" - ? RangeError - : TypeError, - () => Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - day: 18, - offset: offset, - timeZone: "+10:00" - }) - ) -}); - - -// overflow options -var bad = { - year: 2019, - month: 1, - day: 32, - timeZone: "+01:00" -}; -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(bad, { overflow: "reject" })); -assert.sameValue(`${ Temporal.ZonedDateTime.from(bad) }`, "2019-01-31T00:00:00+01:00[+01:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }) }`, "2019-01-31T00:00:00+01:00[+01:00]"); - -// Offset options - -// { offset: 'reject' } throws if offset does not match offset time zone -var obj = { - year: 2020, - month: 3, - day: 8, - hour: 1, - offset: "-04:00", - timeZone: "-08:00" -}; -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj)); -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" })); - -// { offset: 'reject' } throws if offset does not match IANA time zone -var obj = { - year: 2020, - month: 3, - day: 8, - hour: 1, - offset: "-04:00", - timeZone: "UTC" -}; -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj)); -assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" })); -// throw when bad disambiguation -[ - "", - "EARLIER", - "balance", - 3, - null -].forEach(disambiguation => { - assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[UTC]", { disambiguation })); -});