Test invalid Intl.DateTimeFormat options when dateStyle/timeStyle is set (#3886)

Co-authored-by: Ms2ger <Ms2ger@gmail.com>
This commit is contained in:
Ben Allen 2023-08-07 07:32:44 -07:00 committed by GitHub
parent 21c3097f92
commit 5d9dc53a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
// Copyright 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdatetimeformat
description: >
Verifies that constructor throws when dateStyle is combined with explicit format components.
info: |
CreateDateTimeFormat ( newTarget, locales, options, required, defaults )
...
39. Let dateStyle be ? GetOption(options, "dateStyle", string, « "full", "long", "medium", "short" », undefined).
40. Set dateTimeFormat.[[DateStyle]] to dateStyle.
41. Let timeStyle be ? GetOption(options, "timeStyle", string, « "full", "long", "medium", "short" », undefined).
42. Set dateTimeFormat.[[TimeStyle]] to timeStyle.
43. If dateStyle is not undefined or timeStyle is not undefined, then
a. If hasExplicitFormatComponents is true, then
i. Throw a TypeError exception.
---*/
function optionsThrow(options, testName) {
assert.throws(TypeError, function() {
new Intl.DateTimeFormat(undefined, options);
}, testName + ":");
}
optionsThrow({dateStyle: "full", weekday: "long"}, "dateStyle-weekday");
optionsThrow({dateStyle: "full", era: "long"}, "dateStyle-era");
optionsThrow({dateStyle: "full", year: "numeric"}, "dateStyle-year");
optionsThrow({dateStyle: "full", month: "numeric"}, "dateStyle-month");
optionsThrow({dateStyle: "full", day: "numeric"}, "dateStyle-day");
optionsThrow({dateStyle: "full", dayPeriod: "long"}, "dateStyle-dayPeriod");
optionsThrow({dateStyle: "full", hour: "numeric"}, "dateStyle-hour");
optionsThrow({dateStyle: "full", minute: "numeric"}, "dateStyle-minute");
optionsThrow({dateStyle: "full", second: "numeric"}, "dateStyle-second");
optionsThrow({dateStyle: "full", fractionalSecondDigits: 1}, "dateStyle-fractionalSecondDigits");
optionsThrow({dateStyle: "full", timeZoneName: "short"}, "dateStyle-timeZoneName");
optionsThrow({timeStyle: "full", weekday: "long"}, "timeStyle-weekday");
optionsThrow({timeStyle: "full", era: "long"}, "timeStyle-era");
optionsThrow({timeStyle: "full", year: "numeric"}, "timeStyle-year");
optionsThrow({timeStyle: "full", month: "numeric"}, "timeStyle-month");
optionsThrow({timeStyle: "full", day: "numeric"}, "timeStyle-day");
optionsThrow({timeStyle: "full", dayPeriod: "long"}, "timeStyle-dayPeriod");
optionsThrow({timeStyle: "full", hour: "numeric"}, "timeStyle-hour");
optionsThrow({timeStyle: "full", minute: "numeric"}, "timeStyle-minute");
optionsThrow({timeStyle: "full", second: "numeric"}, "timeStyle-second");
optionsThrow({timeStyle: "full", fractionalSecondDigits: 1}, "timeStyle-fractionalSecondDigits");
optionsThrow({timeStyle: "full", timeZoneName: "short"}, "timeStyle-timeZoneName");