Debian Codegraph @

js/src/tests/non262/Intl/NumberFormat/unit-well-formed.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 // Generated by make_intl_data.py. DO NOT EDIT.
4
5 const sanctionedSimpleUnitIdentifiers = [
6 "acre",
7 "bit",
8 "byte",
9 "celsius",
10 "centimeter",
11 "day",
12 "degree",
13 "fahrenheit",
14 "fluid-ounce",
15 "foot",
16 "gallon",
17 "gigabit",
18 "gigabyte",
19 "gram",
20 "hectare",
21 "hour",
22 "inch",
23 "kilobit",
24 "kilobyte",
25 "kilogram",
26 "kilometer",
27 "liter",
28 "megabit",
29 "megabyte",
30 "meter",
31 "microsecond",
32 "mile",
33 "mile-scandinavian",
34 "milliliter",
35 "millimeter",
36 "millisecond",
37 "minute",
38 "month",
39 "nanosecond",
40 "ounce",
41 "percent",
42 "petabyte",
43 "pound",
44 "second",
45 "stone",
46 "terabit",
47 "terabyte",
48 "week",
49 "yard",
50 "year"
51 ];
52
53 const allUnits = [
54 "acceleration-g-force",
55 "acceleration-meter-per-square-second",
56 "angle-arc-minute",
57 "angle-arc-second",
58 "angle-degree",
59 "angle-radian",
60 "angle-revolution",
61 "area-acre",
62 "area-dunam",
63 "area-hectare",
64 "area-square-centimeter",
65 "area-square-foot",
66 "area-square-inch",
67 "area-square-kilometer",
68 "area-square-meter",
69 "area-square-mile",
70 "area-square-yard",
71 "concentr-item",
72 "concentr-karat",
73 "concentr-milligram-ofglucose-per-deciliter",
74 "concentr-millimole-per-liter",
75 "concentr-mole",
76 "concentr-percent",
77 "concentr-permille",
78 "concentr-permillion",
79 "concentr-permyriad",
80 "concentr-portion-per-1e9",
81 "consumption-liter-per-100-kilometer",
82 "consumption-liter-per-kilometer",
83 "consumption-mile-per-gallon",
84 "consumption-mile-per-gallon-imperial",
85 "digital-bit",
86 "digital-byte",
87 "digital-gigabit",
88 "digital-gigabyte",
89 "digital-kilobit",
90 "digital-kilobyte",
91 "digital-megabit",
92 "digital-megabyte",
93 "digital-petabyte",
94 "digital-terabit",
95 "digital-terabyte",
96 "duration-century",
97 "duration-day",
98 "duration-day-person",
99 "duration-decade",
100 "duration-hour",
101 "duration-microsecond",
102 "duration-millisecond",
103 "duration-minute",
104 "duration-month",
105 "duration-month-person",
106 "duration-nanosecond",
107 "duration-night",
108 "duration-quarter",
109 "duration-second",
110 "duration-week",
111 "duration-week-person",
112 "duration-year",
113 "duration-year-person",
114 "electric-ampere",
115 "electric-milliampere",
116 "electric-ohm",
117 "electric-volt",
118 "energy-british-thermal-unit",
119 "energy-calorie",
120 "energy-electronvolt",
121 "energy-foodcalorie",
122 "energy-joule",
123 "energy-kilocalorie",
124 "energy-kilojoule",
125 "energy-kilowatt-hour",
126 "energy-therm-us",
127 "force-kilowatt-hour-per-100-kilometer",
128 "force-newton",
129 "force-pound-force",
130 "frequency-gigahertz",
131 "frequency-hertz",
132 "frequency-kilohertz",
133 "frequency-megahertz",
134 "graphics-dot",
135 "graphics-dot-per-centimeter",
136 "graphics-dot-per-inch",
137 "graphics-em",
138 "graphics-megapixel",
139 "graphics-pixel",
140 "graphics-pixel-per-centimeter",
141 "graphics-pixel-per-inch",
142 "length-astronomical-unit",
143 "length-centimeter",
144 "length-decimeter",
145 "length-earth-radius",
146 "length-fathom",
147 "length-foot",
148 "length-furlong",
149 "length-inch",
150 "length-kilometer",
151 "length-light-year",
152 "length-meter",
153 "length-micrometer",
154 "length-mile",
155 "length-mile-scandinavian",
156 "length-millimeter",
157 "length-nanometer",
158 "length-nautical-mile",
159 "length-parsec",
160 "length-picometer",
161 "length-point",
162 "length-solar-radius",
163 "length-yard",
164 "light-candela",
165 "light-lumen",
166 "light-lux",
167 "light-solar-luminosity",
168 "mass-carat",
169 "mass-dalton",
170 "mass-earth-mass",
171 "mass-grain",
172 "mass-gram",
173 "mass-kilogram",
174 "mass-microgram",
175 "mass-milligram",
176 "mass-ounce",
177 "mass-ounce-troy",
178 "mass-pound",
179 "mass-solar-mass",
180 "mass-stone",
181 "mass-ton",
182 "mass-tonne",
183 "power-gigawatt",
184 "power-horsepower",
185 "power-kilowatt",
186 "power-megawatt",
187 "power-milliwatt",
188 "power-watt",
189 "pressure-atmosphere",
190 "pressure-bar",
191 "pressure-hectopascal",
192 "pressure-inch-ofhg",
193 "pressure-kilopascal",
194 "pressure-megapascal",
195 "pressure-millibar",
196 "pressure-millimeter-ofhg",
197 "pressure-pascal",
198 "pressure-pound-force-per-square-inch",
199 "speed-beaufort",
200 "speed-kilometer-per-hour",
201 "speed-knot",
202 "speed-light-speed",
203 "speed-meter-per-second",
204 "speed-mile-per-hour",
205 "temperature-celsius",
206 "temperature-fahrenheit",
207 "temperature-generic",
208 "temperature-kelvin",
209 "torque-newton-meter",
210 "torque-pound-force-foot",
211 "volume-acre-foot",
212 "volume-barrel",
213 "volume-bushel",
214 "volume-centiliter",
215 "volume-cubic-centimeter",
216 "volume-cubic-foot",
217 "volume-cubic-inch",
218 "volume-cubic-kilometer",
219 "volume-cubic-meter",
220 "volume-cubic-mile",
221 "volume-cubic-yard",
222 "volume-cup",
223 "volume-cup-metric",
224 "volume-deciliter",
225 "volume-dessert-spoon",
226 "volume-dessert-spoon-imperial",
227 "volume-dram",
228 "volume-drop",
229 "volume-fluid-ounce",
230 "volume-fluid-ounce-imperial",
231 "volume-gallon",
232 "volume-gallon-imperial",
233 "volume-hectoliter",
234 "volume-jigger",
235 "volume-liter",
236 "volume-megaliter",
237 "volume-milliliter",
238 "volume-pinch",
239 "volume-pint",
240 "volume-pint-metric",
241 "volume-quart",
242 "volume-quart-imperial",
243 "volume-tablespoon",
244 "volume-teaspoon"
245 ];
246
247 // Test only sanctioned unit identifiers are allowed.
248
249 for (const typeAndUnit of allUnits) {
250 const [_, type, unit] = typeAndUnit.match(/(\w+)-(.+)/);
251
252 let allowed;
253 if (unit.includes("-per-")) {
254 const [numerator, denominator] = unit.split("-per-");
255 allowed = sanctionedSimpleUnitIdentifiers.includes(numerator) &&
256 sanctionedSimpleUnitIdentifiers.includes(denominator);
257 } else {
258 allowed = sanctionedSimpleUnitIdentifiers.includes(unit);
259 }
260
261 if (allowed) {
262 const nf = new Intl.NumberFormat("en", {style: "unit", unit});
263 assertEq(nf.format(1), nf.formatToParts(1).map(p => p.value).join(""));
264 } else {
265 assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {style: "unit", unit}),
266 RangeError, `Missing error for "${typeAndUnit}"`);
267 }
268 }
269
270 if (typeof reportCompare === "function")
271 reportCompare(true, true);