From 5c96724b43b10e30a36a227dbfa6f9775ced6c61 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Wed, 23 Aug 2023 07:49:05 -0700 Subject: [PATCH 1/2] testing for invalid combinations of numeric and non-numeric styles --- ...ctor-options-inconsistent-style-invalid.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js diff --git a/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js b/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js new file mode 100644 index 0000000000..89b2a9b319 --- /dev/null +++ b/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js @@ -0,0 +1,35 @@ +// Copyright 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat +description: Checks handling of a null options argument to the DurationFormat constructor. +info: | + 1.2.1 Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 17. For each row of Table 3, except the header row, in table order, do + a. Let styleSlot be the Style Slot value of the current row. + b. Let displaySlot be the Display Slot value of the current row. + c. Let unit be the Unit value. + d. Let valueList be the Values value. + e. Let digitalBase be the Digital Default value. + f. Let unitOptions be ? GetDurationUnitOptions(unit, options, style, valueList, digitalBase, prevStyle). + + GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle ) + (...) + 6. If prevStyle is "numeric" or "2-digit", then + a. If style is not "numeric" or "2-digit", then + i. Throw a RangeError exception. +features: [Intl.DurationFormat] +---*/ + +var numericStyles = ['numeric', '2-digit']; + +for (var style of numericStyles){ + assert.throws(RangeError, function() { + new Intl.DurationFormat(undefined, { hours: style, minutes: "long"}); + }); + assert.throws(RangeError, function() { + new Intl.DurationFormat(undefined, { minutes: style, milliseconds: "long"}); + }); +} From 60ac2bb63d1dc7eaeb78c46dbd73db3dda4287df Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Wed, 23 Aug 2023 08:37:13 -0700 Subject: [PATCH 2/2] generalized test slightly --- ...uctor-options-inconsistent-style-invalid.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js b/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js index 89b2a9b319..10fd7286c2 100644 --- a/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js +++ b/test/intl402/DurationFormat/constructor-options-inconsistent-style-invalid.js @@ -23,13 +23,23 @@ info: | features: [Intl.DurationFormat] ---*/ -var numericStyles = ['numeric', '2-digit']; +/* -for (var style of numericStyles){ +var durationUnits = ['minutes', 'seconds', 'milliseconds', 'microseconds']; +var duration = { hours: 1, minutes: 2, seconds: 3, milliseconds: 456, microseconds: 789, nanoseconds: 101}; + +for (var durationUnit of durationUnits){ assert.throws(RangeError, function() { - new Intl.DurationFormat(undefined, { hours: style, minutes: "long"}); + new Intl.DurationFormat(undefined, {style: "digital", [durationUnit]: "long"}.format(duration)); }); +} + +*/ + +let timeUnits = ['minutes', 'seconds', 'milliseconds', 'microseconds']; + +for (var timeUnit of timeUnits){ assert.throws(RangeError, function() { - new Intl.DurationFormat(undefined, { minutes: style, milliseconds: "long"}); + new Intl.DurationFormat(undefined, {hours: "numeric", [timeUnit]: "long"}).format({hours: 1, minutes: 2, seconds: 3, milliseconds: 4, microseconds: 5, nanoseconds: 6}); }); }