| 1 |
// |reftest| skip-if(!Intl.hasOwnProperty('DurationFormat')) -- Intl.DurationFormat is not enabled unconditionally |
| 2 |
// Copyright 2023 Igalia, S.L. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-isvaliddurationrecord |
| 7 |
description: Checks that the "long", "short", and "narrow" styles can't be used for units following a unit using the "numeric" or "2-digit" style. |
| 8 |
info: | |
| 9 |
GetDurationUnitOptions (unit, options, baseStyle, stylesList, digitalBase, prevStyle) |
| 10 |
(...) |
| 11 |
6. If prevStyle is "numeric" or "2-digit", then |
| 12 |
a. If style is not "numeric" or "2-digit", then |
| 13 |
i. Throw a RangeError exception. |
| 14 |
features: [Intl.DurationFormat] |
| 15 |
---*/ |
| 16 |
|
| 17 |
let invalidOptions = {}; |
| 18 |
for (const timeUnit of ["hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){ |
| 19 |
invalidOptions[timeUnit] = "numeric"; |
| 20 |
} |
| 21 |
|
| 22 |
for (const timeUnit of ["minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){ |
| 23 |
for (const invalidStyle of ["long", "short", "narrow"]){ |
| 24 |
invalidOptions[timeUnit] = invalidStyle; |
| 25 |
assert.throws(RangeError, function() { |
| 26 |
new Intl.DurationFormat([], invalidOptions); |
| 27 |
}, `${invalidStyle} is an invalid style option value when following a unit with \"numeric\" style`); |
| 28 |
} |
| 29 |
invalidOptions[timeUnit] = "numeric"; |
| 30 |
} |
| 31 |
|
| 32 |
for (const timeUnit of ["hours", "minutes", "seconds"]){ |
| 33 |
invalidOptions[timeUnit] = "2-digit"; |
| 34 |
} |
| 35 |
|
| 36 |
for (const timeUnit of ["minutes", "seconds", "milliseconds"]){ |
| 37 |
for (const invalidStyle of ["long", "short", "narrow"]){ |
| 38 |
invalidOptions[timeUnit] = invalidStyle; |
| 39 |
assert.throws(RangeError, function() { |
| 40 |
new Intl.DurationFormat([], invalidOptions); |
| 41 |
}, `${invalidStyle} is an invalid style option value when following a unit with \"2-digit\" style`); |
| 42 |
} |
| 43 |
invalidOptions[timeUnit] = "2-digit"; |
| 44 |
} |
| 45 |
|
| 46 |
reportCompare(0, 0); |