Backed out 2 changesets (bug 1888310, bug 1884625) for causing failures on browser_ap...
[gecko.git] / js / src / tests / test262 / intl402 / DurationFormat / prototype / format / mixed-non-numeric-styles-es.js
blob33ec1a2776972ff5a0882ac3ceb70eda046a5f17
1 // |reftest| skip -- Intl.DurationFormat is not supported
2 // Copyright 2024 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-Intl.DurationFormat.prototype.format
7 description: Test if format method formats duration correctly with mixed non-numeric settings for unit styles. Compares output from format method to output produced through using NumberFormat and ListFormat as used by DurationFormat.
8 info: |
9   PartitionDurationFormatPattern ( durationFormat, duration )
10   ...
11   9. While done is false, repeat for each row in Table 2 in table order, except the header row:
12     ...
13     k. If value is not 0 or display is not "auto" or displayRequired is "true", then
14       ...
15       v. If style is not "fractional", "numeric", or "2-digit", then
16         1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
17         2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
18         3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
19       ...
20       ix. Let parts be ! PartitionNumberPattern(nf, value).
21   ...
22   14. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
23   15. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
24   ...
25   18. Let formatted be CreatePartsFromList(lf, strings).
27 locale: [es]
28 features: [Intl.DurationFormat]
29 ---*/
31 function formatDuration(locale, duration, dfOpts){
32   let result = [];
33   for (const unit in duration){
34     let nfUnit = unit.substring(0, unit.length - 1);
35     let nf = new Intl.NumberFormat(locale, {style: "unit", unit: nfUnit, unitDisplay: dfOpts[unit]});
36     result.push(nf.format(duration[unit]));
37   }
39   for (const baseStyle of ["long", "short", "narrow"]){
40     let lf = new Intl.ListFormat(locale, {type: "unit", style: baseStyle});
41     let expected = lf.format(result);
42     dfOpts.style = baseStyle;
43     let df = new Intl.DurationFormat(locale, dfOpts);
44     let actual = df.format(duration);
45     assert.sameValue(actual, expected);
46   }
49 const duration = {
50   years: 1,
51   months: 2,
52   weeks: 3,
53   days: 0,
54   hours: 4,
55   minutes: 5,
56   seconds: 6,
57   milliseconds: 7,
58   microseconds: 8,
59   nanoseconds: 9,
62 const locale = "es";
64 formatDuration(locale, duration, {
65   years: "narrow",
66   months: "narrow",
67   weeks: "narrow",
68   days: "short",
69   hours: "short",
70   minutes: "short",
71   seconds: "long",
72   milliseconds: "long",
73   microseconds: "long",
74   nanoseconds: "narrow", });
76 formatDuration(locale, duration, {
77   years: "long",
78   months: "short",
79   weeks: "narrow",
80   days: "long",
81   hours: "short",
82   minutes: "narrow",
83   seconds: "long",
84   milliseconds: "short",
85   microseconds: "narrow",
86   nanoseconds: "long", });
88 reportCompare(0, 0);