Skip to content

Commit

Permalink
Updated expected error in NumberFormat constructor per current spec
Browse files Browse the repository at this point in the history
  • Loading branch information
anba committed Jun 24, 2020
1 parent b78c6d2 commit 02ab047
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 6 additions & 7 deletions test/intl402/NumberFormat/constructor-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ info: |
5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
6. If currency is not undefined, then
a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
9. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
10. If unit is not undefined, then
7. If style is "currency" and currency is undefined, throw a TypeError exception.
...
10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
11. If unit is not undefined, then
a. If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
12. If style is "currency", then
a. If currency is undefined, throw a TypeError exception.
13. If style is "unit", then
a. If unit is undefined, throw a TypeError exception.
12. If style is "unit" and unit is undefined, throw a TypeError exception.
features: [Intl.NumberFormat-unified]
---*/

assert.throws(RangeError, () => {
assert.throws(TypeError, () => {
new Intl.NumberFormat([], { style: "currency", unit: "test" })
});

Expand Down
15 changes: 14 additions & 1 deletion test/intl402/NumberFormat/constructor-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ assert.throws(TypeError, () => {
});

for (const unit of ["test", "MILE", "kB"]) {
for (const style of [undefined, "decimal", "currency", "unit"]) {
// Throws RangeError for invalid unit identifier.
for (const style of [undefined, "decimal", "unit"]) {
assert.throws(RangeError, () => {
new Intl.NumberFormat([], { style, unit })
}, `{ style: ${style}, unit: ${unit} }`);
}

const style = "currency";

// Throws TypeError because "currency" option is missing.
assert.throws(TypeError, () => {
new Intl.NumberFormat([], { style, unit })
}, `{ style: ${style}, unit: ${unit} }`);

// Throws RangeError for invalid unit identifier.
assert.throws(RangeError, () => {
new Intl.NumberFormat([], { style, unit, currency: "USD" })
}, `{ style: ${style}, unit: ${unit} }`);
}

const nf = new Intl.NumberFormat([], {
Expand Down

0 comments on commit 02ab047

Please sign in to comment.