Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / intl402 / DurationFormat / prototype / formatToParts / negative-duration-formatToParts-style-digital-en.js
blob6978739ac389f5fb61aad652381ba238fe40d932
1 // |reftest| skip -- Intl.DurationFormat is not supported
2 // Copyright (C) 2023 AndrĂ© Bargull. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-Intl.DurationFormat.prototype.formatToParts
7 description: >
8   Test formatToParts method with negative duration and "digital" style
9 locale: [en]
10 includes: [testIntl.js]
11 features: [Intl.DurationFormat]
12 ---*/
14 function compare(actual, expected, message) {
15   assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
16   assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
17   assert.sameValue(actual.length, expected.length, `${message}: length`);
19   for (let i = 0; i < expected.length; ++i) {
20     let actualEntry = actual[i];
21     let expectedEntry = expected[i];
23     assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
24     assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
25     assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
26     if ("unit" in expectedEntry) {
27       assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
28     }
29   }
32 const style = "digital";
34 const duration = {
35   years: -1,
36   months: -2,
37   weeks: -3,
38   days: -4,
39   hours: -5,
40   minutes: -6,
41   seconds: -7,
42   milliseconds: -123,
43   microseconds: -456,
44   nanoseconds: -789,
47 const expected = partitionDurationFormatPattern(duration, style);
49 const df = new Intl.DurationFormat("en", { style });
50 compare(df.formatToParts(duration), expected, `Using style : ${style}`);
52 reportCompare(0, 0);