units.js (1726B)
1 // Copyright (C) 2021 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-intl.supportedvaluesof 6 description: > 7 The returned "unit" values are sorted, unique, and well-formed. 8 info: | 9 Intl.supportedValuesOf ( key ) 10 11 1. Let key be ? ToString(key). 12 ... 13 7. Else if key is "unit", then 14 a. Let list be ! AvailableUnits( ). 15 ... 16 9. Return ! CreateArrayFromList( list ). 17 18 AvailableUnits ( ) 19 The AvailableUnits abstract operation returns a List, ordered as if an Array 20 of the same values had been sorted using %Array.prototype.sort% using 21 undefined as comparefn, that contains the unique values of simple unit 22 identifiers listed in every row of Table 1, except the header row. 23 includes: [compareArray.js, testIntl.js] 24 features: [Intl-enumeration, Array.prototype.includes] 25 ---*/ 26 27 const units = Intl.supportedValuesOf("unit"); 28 29 assert(Array.isArray(units), "Returns an Array object."); 30 assert.sameValue(Object.getPrototypeOf(units), Array.prototype, 31 "The array prototype is Array.prototype"); 32 33 const otherUnits = Intl.supportedValuesOf("unit"); 34 assert.notSameValue(otherUnits, units, 35 "Returns a new array object for each call."); 36 37 assert.compareArray(units, otherUnits.sort(), 38 "The array is sorted."); 39 40 assert.sameValue(new Set(units).size, units.length, 41 "The array doesn't contain duplicates."); 42 43 const simpleSanctioned = allSimpleSanctionedUnits(); 44 45 for (let unit of units) { 46 assert(simpleSanctioned.includes(unit), `${unit} is a simple, sanctioned unit`); 47 assert(!unit.includes("-per-"), `${unit} isn't a compound unit`); 48 } 49 50 reportCompare(0, 0);