summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts')
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/branding.js25
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/browser.js0
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js47
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js49
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js49
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js49
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js49
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js40
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-negative-duration-throws.js23
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/length.js39
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/name.js29
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js50
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js52
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js52
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js52
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js52
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js24
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/prop-desc.js24
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/shell.js24
-rw-r--r--js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js25
20 files changed, 754 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/branding.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/branding.js
new file mode 100644
index 0000000000..179fdcb064
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/branding.js
@@ -0,0 +1,25 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Verifies the branding check for the "formatToParts" function of the DurationFormat prototype object.
+features: [Intl.DurationFormat]
+---*/
+
+const formatToParts = Intl.DurationFormat.prototype.formatToParts;
+
+assert.sameValue(typeof formatToParts, "function");
+
+assert.throws(TypeError, () => formatToParts.call(undefined, { years : 2 }), "undefined");
+assert.throws(TypeError, () => formatToParts.call(null, { years : 2 }), "null");
+assert.throws(TypeError, () => formatToParts.call(true, { years : 2 }), "true");
+assert.throws(TypeError, () => formatToParts.call("", { years : 2 }), "empty string");
+assert.throws(TypeError, () => formatToParts.call(Symbol(), { years : 2 }), "symbol");
+assert.throws(TypeError, () => formatToParts.call(1, { years : 2 }), "1");
+assert.throws(TypeError, () => formatToParts.call({}, { years : 2 }), "plain object");
+assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat, { years : 2 } ), "Intl.DurationFormat");
+assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat.prototype, { years : 2 }), "Intl.DurationFormat.prototype");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/browser.js
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js
new file mode 100644
index 0000000000..03b16dc627
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-default-en.js
@@ -0,0 +1,47 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+// Utils functions
+function* zip(a, b) {
+ for (let i = 0; i < a.length; ++i) {
+ yield [i, a[i], b[i]];
+ }
+}
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
+ // assertions
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ if (expectedEntry.unit) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+const duration = {
+ hours: 7,
+ minutes: 8,
+ seconds: 9,
+ milliseconds: 123,
+ microseconds: 456,
+ nanoseconds: 789,
+};
+
+const expected = partitionDurationFormatPattern(duration);
+
+let df = new Intl.DurationFormat('en');
+compare(df.formatToParts(duration), expected, `Using style : default`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js
new file mode 100644
index 0000000000..0e8246f212
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-digital-en.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+// Utils functions
+function* zip(a, b) {
+ for (let i = 0; i < a.length; ++i) {
+ yield [i, a[i], b[i]];
+ }
+}
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
+ // assertions
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ if (expectedEntry.unit) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+const duration = {
+ hours: 7,
+ minutes: 8,
+ seconds: 9,
+ milliseconds: 123,
+ microseconds: 456,
+ nanoseconds: 789,
+};
+
+const style = "digital";
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+let df = new Intl.DurationFormat('en', { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js
new file mode 100644
index 0000000000..a54ddb61f8
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-long-en.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+// Utils functions
+function* zip(a, b) {
+ for (let i = 0; i < a.length; ++i) {
+ yield [i, a[i], b[i]];
+ }
+}
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
+ // assertions
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ if (expectedEntry.unit) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+const duration = {
+ hours: 7,
+ minutes: 8,
+ seconds: 9,
+ milliseconds: 123,
+ microseconds: 456,
+ nanoseconds: 789,
+};
+
+const style = "long";
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+let df = new Intl.DurationFormat('en', { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js
new file mode 100644
index 0000000000..feff8fda60
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-narrow-en.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+// Utils functions
+function* zip(a, b) {
+ for (let i = 0; i < a.length; ++i) {
+ yield [i, a[i], b[i]];
+ }
+}
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
+ // assertions
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ if (expectedEntry.unit) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+const duration = {
+ hours: 7,
+ minutes: 8,
+ seconds: 9,
+ milliseconds: 123,
+ microseconds: 456,
+ nanoseconds: 789,
+};
+
+const style = "narrow";
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+let df = new Intl.DurationFormat('en', { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js
new file mode 100644
index 0000000000..605448bde0
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-style-short-en.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 Igalia S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks basic handling of formatToParts, using long, short,narrow and digital styles.
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+// Utils functions
+function* zip(a, b) {
+ for (let i = 0; i < a.length; ++i) {
+ yield [i, a[i], b[i]];
+ }
+}
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
+ // assertions
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ if (expectedEntry.unit) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+const duration = {
+ hours: 7,
+ minutes: 8,
+ seconds: 9,
+ milliseconds: 123,
+ microseconds: 456,
+ nanoseconds: 789,
+};
+
+const style = "short";
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+let df = new Intl.DurationFormat('en', { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js
new file mode 100644
index 0000000000..7f3105086f
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js
@@ -0,0 +1,40 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ "formatToParts" basic tests for invalid arguments that should throw TypeError exception.
+info: |
+ Intl.DurationFormat.prototype.formatToParts(duration)
+ (...)
+ 3. Let record be ? ToDurationRecord(duration)
+features: [Intl.DurationFormat]
+---*/
+
+const df = new Intl.DurationFormat();
+const testOptions = [ "years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"];
+
+assert.throws(TypeError, () => { df.formatToParts(undefined) }, "undefined" );
+assert.throws(TypeError, () => { df.formatToParts(null) }, "null");
+assert.throws(TypeError, () => { df.formatToParts(true) }, "true");
+assert.throws(TypeError, () => { df.formatToParts(-12) }, "-12");
+assert.throws(TypeError, () => { df.formatToParts(-12n) }, "-12n");
+assert.throws(TypeError, () => { df.formatToParts(1) }, "1");
+assert.throws(TypeError, () => { df.formatToParts(2n) }, "2n");
+assert.throws(TypeError, () => { df.formatToParts({}) }, "plain object");
+assert.throws(TypeError, () => { df.formatToParts({ year: 1 }) }, "unsuported property");
+assert.throws(TypeError, () => { df.formatToParts({ years: undefined }) }, "supported property set undefined");
+assert.throws(TypeError, () => { df.formatToParts(Symbol())}, "symbol");
+assert.throws(RangeError, () => { df.formatToParts("bad string")}, "bad string");
+
+testOptions.forEach( option => {
+ assert.throws(RangeError, () => { df.formatToParts({ [option]: 2.5 })}, " duration properties must be integers");
+});
+
+testOptions.forEach( option => {
+ assert.throws(RangeError, () => { df.formatToParts({ [option]: -Infinity })}, " duration properties must be integers");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-negative-duration-throws.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-negative-duration-throws.js
new file mode 100644
index 0000000000..ede7dd8839
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/invalid-negative-duration-throws.js
@@ -0,0 +1,23 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: formatToParts basic tests for invalid negative duration objects that should throw RangeError exception.
+features: [Intl.DurationFormat]
+---*/
+
+const df = new Intl.DurationFormat();
+
+assert.throws(RangeError, () => { df.formatToParts({
+ hours : -1,
+ minutes: 10
+}), "Throws when mixing negative and positive values" });
+
+assert.throws(RangeError, () => { df.formatToParts({
+ hours : 2,
+ minutes: -10
+}), "Throws when mixing negative and positive values" });
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/length.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/length.js
new file mode 100644
index 0000000000..c131c7e239
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/length.js
@@ -0,0 +1,39 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.datetimeformat.prototype.formatToParts
+description: >
+ Intl.DateTimeFormat.prototype.formatToParts.length is 1.
+info: |
+ Intl.DateTimeFormat.prototype.formatToParts ( date )
+
+ 17 ECMAScript Standard Built-in Objects:
+
+ Every built-in function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description. Optional parameters
+ (which are indicated with brackets: [ ]) or rest parameters (which
+ are shown using the form «...name») are not included in the default
+ argument count.
+ Unless otherwise specified, the length property of a built-in function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+
+features: [Intl.DurationFormat]
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Intl.DateTimeFormat.prototype.formatToParts.length, 1);
+
+verifyProperty(Intl.DurationFormat.prototype.formatToParts, "length", {
+ value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/name.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/name.js
new file mode 100644
index 0000000000..dc21910462
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/name.js
@@ -0,0 +1,29 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Checks the "name" property of Intl.DurationFormat.prototype.formatToParts().
+info: |
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+
+includes: [propertyHelper.js]
+features: [Intl.DurationFormat]
+---*/
+
+verifyProperty(Intl.DurationFormat.prototype.formatToParts, "name", {
+ value: "formatToParts",
+ writable: false,
+ enumerable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js
new file mode 100644
index 0000000000..bfc182c34b
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-default-en.js
@@ -0,0 +1,50 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Test formatToParts method with negative duration and default style
+locale: [en-US]
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (let i = 0; i < expected.length; ++i) {
+ let actualEntry = actual[i];
+ let expectedEntry = expected[i];
+
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
+ if ("unit" in expectedEntry) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+
+const duration = {
+ years: -1,
+ months: -2,
+ weeks: -3,
+ days: -4,
+ hours: -5,
+ minutes: -6,
+ seconds: -7,
+ milliseconds: -123,
+ microseconds: -456,
+ nanoseconds: -789,
+};
+
+const expected = partitionDurationFormatPattern(duration);
+
+const df = new Intl.DurationFormat("en");
+compare(df.formatToParts(duration), expected, `Using style : default`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js
new file mode 100644
index 0000000000..52a40072ba
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-digital-en.js
@@ -0,0 +1,52 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Test formatToParts method with negative duration and "digital" style
+locale: [en-US]
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (let i = 0; i < expected.length; ++i) {
+ let actualEntry = actual[i];
+ let expectedEntry = expected[i];
+
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
+ if ("unit" in expectedEntry) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+
+const style = "digital";
+
+const duration = {
+ years: -1,
+ months: -2,
+ weeks: -3,
+ days: -4,
+ hours: -5,
+ minutes: -6,
+ seconds: -7,
+ milliseconds: -123,
+ microseconds: -456,
+ nanoseconds: -789,
+};
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+const df = new Intl.DurationFormat("en", { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js
new file mode 100644
index 0000000000..3756db8a84
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-long-en.js
@@ -0,0 +1,52 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Test formatToParts method with negative duration and "long" style
+locale: [en-US]
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (let i = 0; i < expected.length; ++i) {
+ let actualEntry = actual[i];
+ let expectedEntry = expected[i];
+
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
+ if ("unit" in expectedEntry) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+
+const style = "long";
+
+const duration = {
+ years: -1,
+ months: -2,
+ weeks: -3,
+ days: -4,
+ hours: -5,
+ minutes: -6,
+ seconds: -7,
+ milliseconds: -123,
+ microseconds: -456,
+ nanoseconds: -789,
+};
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+const df = new Intl.DurationFormat("en", { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js
new file mode 100644
index 0000000000..a9717ce67a
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-narrow-en.js
@@ -0,0 +1,52 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Test formatToParts method with negative duration and "narrow" style
+locale: [en-US]
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (let i = 0; i < expected.length; ++i) {
+ let actualEntry = actual[i];
+ let expectedEntry = expected[i];
+
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
+ if ("unit" in expectedEntry) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+
+const style = "narrow";
+
+const duration = {
+ years: -1,
+ months: -2,
+ weeks: -3,
+ days: -4,
+ hours: -5,
+ minutes: -6,
+ seconds: -7,
+ milliseconds: -123,
+ microseconds: -456,
+ nanoseconds: -789,
+};
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+const df = new Intl.DurationFormat("en", { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js
new file mode 100644
index 0000000000..bc2ed69c5b
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/negative-duration-formatToParts-style-short-en.js
@@ -0,0 +1,52 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2023 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Test formatToParts method with negative duration and "short" style
+locale: [en-US]
+includes: [testIntl.js]
+features: [Intl.DurationFormat]
+---*/
+
+function compare(actual, expected, message) {
+ assert.sameValue(Array.isArray(expected), true, `${message}: expected is Array`);
+ assert.sameValue(Array.isArray(actual), true, `${message}: actual is Array`);
+ assert.sameValue(actual.length, expected.length, `${message}: length`);
+
+ for (let i = 0; i < expected.length; ++i) {
+ let actualEntry = actual[i];
+ let expectedEntry = expected[i];
+
+ assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
+ assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
+ assert.sameValue("unit" in actualEntry, "unit" in expectedEntry, `unit for entry ${i}`);
+ if ("unit" in expectedEntry) {
+ assert.sameValue(actualEntry.unit, expectedEntry.unit, `unit for entry ${i}`);
+ }
+ }
+}
+
+const style = "short";
+
+const duration = {
+ years: -1,
+ months: -2,
+ weeks: -3,
+ days: -4,
+ hours: -5,
+ minutes: -6,
+ seconds: -7,
+ milliseconds: -123,
+ microseconds: -456,
+ nanoseconds: -789,
+};
+
+const expected = partitionDurationFormatPattern(duration, style);
+
+const df = new Intl.DurationFormat("en", { style });
+compare(df.formatToParts(duration), expected, `Using style : ${style}`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js
new file mode 100644
index 0000000000..b845cabe35
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/not-a-constructor.js
@@ -0,0 +1,24 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: >
+ Intl.DurationFormat.prototype.formatToParts does not implement [[Construct]], is not new-able
+info: |
+ Built-in function objects that are not identified as constructors do not implement the
+ [[Construct]] internal method unless otherwise specified in the description of a particular
+ function.
+includes: [isConstructor.js]
+features: [Reflect.construct, Intl.DurationFormat]
+---*/
+
+assert.throws(TypeError, () => {
+ new Intl.DurationFormat.prototype.formatToParts();
+}, "Calling as constructor");
+
+assert.sameValue(isConstructor(Intl.DurationFormat.prototype.formatToParts), false,
+ "isConstructor(Intl.DurationFormat.prototype.formatToParts)");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/prop-desc.js
new file mode 100644
index 0000000000..3c32931386
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/prop-desc.js
@@ -0,0 +1,24 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-Intl.DurationFormat.prototype.formatToParts
+description: Property descriptor of Intl.DurationFormat.prototype.formatToParts
+includes: [propertyHelper.js]
+features: [Intl.DurationFormat]
+---*/
+
+assert.sameValue(
+ typeof Intl.DurationFormat.prototype.formatToParts,
+ 'function',
+ '`typeof Intl.DurationFormat.prototype.formatToParts` is `function`'
+);
+
+verifyProperty(Intl.DurationFormat.prototype, 'formatToParts', {
+ enumerable: false,
+ writable: true,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/shell.js
@@ -0,0 +1,24 @@
+// GENERATED, DO NOT EDIT
+// file: isConstructor.js
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+ Test if a given function is a constructor function.
+defines: [isConstructor]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js
new file mode 100644
index 0000000000..d091b49dd2
--- /dev/null
+++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js
@@ -0,0 +1,25 @@
+// |reftest| skip -- Intl.DurationFormat is not supported
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.DurationFormat.prototype.format
+description: basic tests internal slot initialization and call receiver errors
+info: |
+ Intl.DurationFormat.prototype.formatToParts ( duration )
+ (...)
+ 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
+features: [Intl.DurationFormat]
+---*/
+
+const df = new Intl.DurationFormat();
+
+// Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
+let f = df["formatToParts"];
+
+assert.sameValue(typeof f, "function");
+assert.throws(TypeError, () => {
+ f({ hours: 1, minutes: 46, seconds: 40 });
+});
+
+reportCompare(0, 0);