diff options
Diffstat (limited to 'js/src/tests/test262/intl402/Intl/supportedValuesOf/units-accepted-by-NumberFormat.js')
-rw-r--r-- | js/src/tests/test262/intl402/Intl/supportedValuesOf/units-accepted-by-NumberFormat.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Intl/supportedValuesOf/units-accepted-by-NumberFormat.js b/js/src/tests/test262/intl402/Intl/supportedValuesOf/units-accepted-by-NumberFormat.js new file mode 100644 index 0000000000..0132f569b2 --- /dev/null +++ b/js/src/tests/test262/intl402/Intl/supportedValuesOf/units-accepted-by-NumberFormat.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.supportedvaluesof +description: > + The returned "unit" values can be used with NumberFormat. +info: | + Intl.supportedValuesOf ( key ) + + 1. Let key be ? ToString(key). + ... + 7. Else if key is "unit", then + a. Let list be ! AvailableUnits( ). + ... + 9. Return ! CreateArrayFromList( list ). + + AvailableUnits ( ) + The AvailableUnits abstract operation returns a List, ordered as if an Array + of the same values had been sorted using %Array.prototype.sort% using + undefined as comparefn, that contains the unique values of simple unit + identifiers listed in every row of Table 1, except the header row. +includes: [testIntl.js] +locale: [en] +features: [Intl-enumeration, Array.prototype.includes] +---*/ + +const units = Intl.supportedValuesOf("unit"); + +for (let unit of units) { + let obj = new Intl.NumberFormat("en", {style: "unit", unit}); + assert.sameValue(obj.resolvedOptions().unit, unit, + `${unit} is supported by NumberFormat`); +} + +for (let unit of allSimpleSanctionedUnits()) { + let obj = new Intl.NumberFormat("en", {style: "unit", unit}); + if (obj.resolvedOptions().unit === unit) { + assert(units.includes(unit), + `${unit} supported but not returned by supportedValuesOf`); + } else { + assert(!units.includes(unit), + `${unit} not supported but returned by supportedValuesOf`); + } +} + +reportCompare(0, 0); |