-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to verify that use of "long", "short", or "narrow" styles…
… for units following units using "numeric" or "2-digit" styles throws
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
test/intl402/DurationFormat/constructor-options-style-conflict.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-isvaliddurationrecord | ||
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. | ||
info: | | ||
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] | ||
---*/ | ||
|
||
let invalidOptions = {}; | ||
for (const timeUnit of ["hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){ | ||
invalidOptions[timeUnit] = "numeric"; | ||
} | ||
|
||
for (const timeUnit of ["minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"]){ | ||
for (const invalidStyle of ["long", "short", "narrow"]){ | ||
invalidOptions[timeUnit] = invalidStyle; | ||
assert.throws(RangeError, function() { | ||
new Intl.DurationFormat([], invalidOptions); | ||
}, `${invalidStyle} is an invalid style option value when following a unit with \"numeric\" style`); | ||
} | ||
invalidOptions[timeUnit] = "numeric"; | ||
} | ||
|
||
for (const timeUnit of ["hours", "minutes", "seconds"]){ | ||
invalidOptions[timeUnit] = "2-digit"; | ||
} | ||
|
||
for (const timeUnit of ["minutes", "seconds", "milliseconds"]){ | ||
for (const invalidStyle of ["long", "short", "narrow"]){ | ||
invalidOptions[timeUnit] = invalidStyle; | ||
assert.throws(RangeError, function() { | ||
new Intl.DurationFormat([], invalidOptions); | ||
}, `${invalidStyle} is an invalid style option value when following a unit with \"2-digit\" style`); | ||
} | ||
invalidOptions[timeUnit] = "2-digit"; | ||
} |