diff options
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat/prototype')
61 files changed, 1845 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/prop-desc.js new file mode 100644 index 0000000000..f0f66bafa2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/prop-desc.js @@ -0,0 +1,35 @@ +// |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 +description: > + "constructor" property of Intl.DurationFormat.prototype. +info: | + Intl.DurationFormat.prototype.constructor + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +features: [Intl.DurationFormat] +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.DurationFormat.prototype, "constructor", { + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/shell.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/value.js b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/value.js new file mode 100644 index 0000000000..c984b7829e --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/value.js @@ -0,0 +1,15 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.DurationFormat +description: > + Tests that Intl.DurationFormat.prototype.constructor is the Intl.DurationFormat. + +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(Intl.DurationFormat.prototype.constructor, Intl.DurationFormat, "Intl.DurationFormat.prototype.constructor is not the same as Intl.DurationFormat"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/branding.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/branding.js new file mode 100644 index 0000000000..acaccd554b --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/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.format +description: Verifies the branding check for the "format" function of the DurationFormat prototype object. +features: [Intl.DurationFormat] +---*/ + +const format = Intl.DurationFormat.prototype.format; + +assert.sameValue(typeof format, "function"); + +assert.throws(TypeError, () => format.call(undefined, { years : 2 }), "undefined"); +assert.throws(TypeError, () => format.call(null, { years : 2 }), "null"); +assert.throws(TypeError, () => format.call(true, { years : 2 }), "true"); +assert.throws(TypeError, () => format.call("", { years : 2 }), "empty string"); +assert.throws(TypeError, () => format.call(Symbol(), { years : 2 }), "symbol"); +assert.throws(TypeError, () => format.call(1, { years : 2 }), "1"); +assert.throws(TypeError, () => format.call({}, { years : 2 }), "plain object"); +assert.throws(TypeError, () => format.call(Intl.DurationFormat, { years : 2 } ), "Intl.DurationFormat"); +assert.throws(TypeError, () => format.call(Intl.DurationFormat.prototype, { years : 2 }), "Intl.DurationFormat.prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js new file mode 100644 index 0000000000..ed9c268b63 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js @@ -0,0 +1,31 @@ +// |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: > + "format" basic tests for invalid arguments that should throw TypeError exception. +info: | + Intl.DurationFormat.prototype.format(duration) + (...) + 3. Let record be ? ToDurationRecord(duration) +features: [Intl.DurationFormat] +---*/ + +const df = new Intl.DurationFormat(); + +assert.throws(TypeError, () => { df.format(undefined) }, "undefined" ); +assert.throws(TypeError, () => { df.format(null) }, "null"); +assert.throws(TypeError, () => { df.format(true) }, "true"); +assert.throws(TypeError, () => { df.format(-12) }, "-12"); +assert.throws(TypeError, () => { df.format(-12n) }, "-12n"); +assert.throws(TypeError, () => { df.format(1) }, "1"); +assert.throws(TypeError, () => { df.format(2n) }, "2n"); +assert.throws(TypeError, () => { df.format({}) }, "plain object"); +assert.throws(TypeError, () => { df.format({ year: 1 }) }, "unsuported property"); +assert.throws(TypeError, () => { df.format({ years: undefined }) }, "supported property set undefined"); +assert.throws(TypeError, () => { df.format(Symbol())}, "symbol"); +assert.throws(RangeError, () => { df.format("bad string")}, "bad string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-negative-duration-throws.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-negative-duration-throws.js new file mode 100644 index 0000000000..b349ee52f7 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/invalid-negative-duration-throws.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: format basic tests for invalid negative duration objects that should throw RangeError exception. +features: [Intl.DurationFormat] +---*/ + + + +const df = new Intl.DurationFormat(); + +assert.throws(RangeError, () => { df.format({ + hours : -1, + minutes: 10 +}), "Throws when mixing negative and positive values" }); + +assert.throws(RangeError, () => { df.format({ + hours : 2, + minutes: -10 +}), "Throws when mixing negative and positive values" }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/length.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/length.js new file mode 100644 index 0000000000..073a761a32 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/length.js @@ -0,0 +1,37 @@ +// |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.format +description: > + Intl.DurationFormat.prototype.format.length is 1. +info: | + Intl.DurationFormat.prototype.format ( duration ) + + 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] +---*/ + +verifyProperty(Intl.DurationFormat.prototype.format, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/name.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/name.js new file mode 100644 index 0000000000..57a2250fd2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/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.format +description: Checks the "name" property of Intl.DurationFormat.prototype.format(). +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.format, "name", { + value: "format", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js new file mode 100644 index 0000000000..c6b58a5dfc --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-default-en.js @@ -0,0 +1,36 @@ +// |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.format +description: > + Test format method with negative duration and default style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration); + +const df = new Intl.DurationFormat("en"); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using default style option` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js new file mode 100644 index 0000000000..83eb5b4639 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-duration-style-short-en.js @@ -0,0 +1,38 @@ +// |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.format +description: > + Test format method with negative duration and "short" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "short"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js new file mode 100644 index 0000000000..c9f119c368 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-digital-en.js @@ -0,0 +1,38 @@ +// |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.format +description: > + Test format method with negative duration and "digital" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "digital"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js new file mode 100644 index 0000000000..fe074d488e --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-long-en.js @@ -0,0 +1,38 @@ +// |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.format +description: > + Test format method with negative duration and "long" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "long"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js new file mode 100644 index 0000000000..4d1db5dc67 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/negative-durationstyle-narrow-en.js @@ -0,0 +1,38 @@ +// |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.format +description: > + Test format method with negative duration and "narrow" style +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "narrow"; + +const duration = { + years: -1, + months: -2, + weeks: -3, + days: -3, + hours: -4, + minutes: -5, + seconds: -6, + milliseconds: -7, + microseconds: -8, + nanoseconds: -9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue( + df.format(duration), + expected, + `DurationFormat format output using ${style} style option` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/not-a-constructor.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/not-a-constructor.js new file mode 100644 index 0000000000..a029decc62 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/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.format +description: > + Intl.DurationFormat.prototype.format 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.format(); +}, "Calling as constructor"); + +assert.sameValue(isConstructor(Intl.DurationFormat.prototype.format), false, + "isConstructor(Intl.DurationFormat.prototype.format)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js new file mode 100644 index 0000000000..dc5ad4ea84 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js @@ -0,0 +1,44 @@ +// |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.format +description: > + The correct separator is used for numeric hours with zero minutes and non-zero seconds. +locale: [en-US] +features: [Intl.DurationFormat] +---*/ + +const df = new Intl.DurationFormat("en", { + // hours must be numeric, so that a time separator is used for the following units. + hours: "numeric", +}); + +const lf = new Intl.ListFormat("en", { + type: "unit", + style: "short", +}); + +const duration = { + hours: 1, + + // Minutes is omitted from the output when its value is zero. + minutes: 0, + + // Either seconds or sub-seconds must be non-zero. + seconds: 3, +}; + +const expected = lf.format([ + new Intl.NumberFormat("en", {minimumIntegerDigits: 1}).format(duration.hours), + new Intl.NumberFormat("en", {minimumIntegerDigits: 2}).format(duration.seconds), +]); + +assert.sameValue( + df.format(duration), + expected, + `No time separator is used when minutes is zero` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js new file mode 100644 index 0000000000..5518450d6a --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/precision-exact-mathematical-values.js @@ -0,0 +1,96 @@ +// |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.format +description: > + PartitionDurationFormatPattern computes on exact mathematical values. +info: | + PartitionDurationFormatPattern ( durationFormat, duration ) + ... + 4. While done is false, repeat for each row in Table 1 in order, except the header row: + ... + j. If unit is "seconds", "milliseconds", or "microseconds", then + i. If unit is "seconds", then + 1. Let nextStyle be durationFormat.[[MillisecondsStyle]]. + ... + iv. If nextStyle is "numeric", then + 1. If unit is "seconds", then + a. Set value to value + duration.[[Milliseconds]] / 10^3 + duration.[[Microseconds]] / 10^6 + duration.[[Nanoseconds]] / 10^9. + ... + l. If value is not 0 or display is not "auto", then + ii. If style is "2-digit" or "numeric", then + ... + 7. Let parts be ! PartitionNumberPattern(nf, value). + ... + +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const durations = [ + // 10000000 + (1 / 10^9) + // = 10000000.000000001 + { + seconds: 10_000_000, + nanoseconds: 1, + }, + + // 9007199254740991 + (9007199254740991 / 10^3) + (9007199254740991 / 10^6) + (9007199254740991 / 10^9) + // = 9.016215470202185986731991 × 10^15 + { + seconds: Number.MAX_SAFE_INTEGER, + milliseconds: Number.MAX_SAFE_INTEGER, + microseconds: Number.MAX_SAFE_INTEGER, + nanoseconds: Number.MAX_SAFE_INTEGER, + }, + { + seconds: Number.MIN_SAFE_INTEGER, + milliseconds: Number.MIN_SAFE_INTEGER, + microseconds: Number.MIN_SAFE_INTEGER, + nanoseconds: Number.MIN_SAFE_INTEGER, + }, + + // 1 + (2 / 10^3) + (3 / 10^6) + (9007199254740991 / 10^9) + // = 9.007200256743991 × 10^6 + { + seconds: 1, + milliseconds: 2, + microseconds: 3, + nanoseconds: Number.MAX_SAFE_INTEGER, + }, + + // 9007199254740991 + (10^3 / 10^3) + (10^6 / 10^6) + (10^9 / 10^9) + // = 9007199254740991 + 3 + // = 9007199254740994 + { + seconds: Number.MAX_SAFE_INTEGER, + milliseconds: 10 ** 3, + microseconds: 10 ** 6, + nanoseconds: 10 ** 9, + }, + + // ~1.7976931348623157e+308 / 10^9 + // = ~1.7976931348623157 × 10^299 + { + seconds: 0, + milliseconds: 0, + microseconds: 0, + nanoseconds: Number.MAX_VALUE, + }, +]; + +const df = new Intl.DurationFormat("en", {style: "digital"}); + +for (let duration of durations) { + let expected = formatDurationFormatPattern(duration, "digital"); + assert.sameValue( + df.format(duration), + expected, + `Duration is ${JSON.stringify(duration)}` + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/prop-desc.js new file mode 100644 index 0000000000..ebb842ae83 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/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.format +description: Property descriptor of Intl.DurationFormat.prototype.format +includes: [propertyHelper.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue( + typeof Intl.DurationFormat.prototype.format, + 'function', + '`typeof Intl.DurationFormat.prototype.format` is `function`' +); + +verifyProperty(Intl.DurationFormat.prototype, 'format', { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/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/format/style-default-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js new file mode 100644 index 0000000000..6eb5c4999e --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-default-en.js @@ -0,0 +1,31 @@ +// |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.format +description: Test if format method formats duration correctly with different "style" arguments +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const expected = formatDurationFormatPattern(duration); + +const df = new Intl.DurationFormat("en"); +assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using default style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js new file mode 100644 index 0000000000..4f34d50aa9 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-en.js @@ -0,0 +1,34 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright 2022 Igalia, S.L. All rights reserved. +// Copyright 2023 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: Test if format method formats duration correctly with different "style" arguments +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "digital"; + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js new file mode 100644 index 0000000000..631e6c36eb --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js @@ -0,0 +1,71 @@ +// |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-partitiondurationformatpattern +description: > + Test to ensure that correct number of fractional digits is displayed (i.e. however many are necessary to represent the data fully) if the fractionalDigits option is left *undefined* + +info: | + 4. If durationFormat.[[FractionalDigits]] is undefined, then + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", 0). + 5. Else, + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). +features: [Intl.DurationFormat] +---*/ + + +const durationNano = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222, + nanoseconds: 333 +}; + +const durationMicro = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222 +}; + +const durationMill = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111 +}; + +const durationNoSubsecond = { + hours: 1, + minutes: 22, + seconds: 33 +}; + +const durationSevenFractional = { + hours: 2, + minutes: 30, + seconds: 10, + milliseconds: 111, + microseconds: 220, + nanoseconds: 300 +}; + +const style = "digital"; +const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: undefined}); + +assert.sameValue(df.format(durationNano), "1:22:33.111222333", `format output with nanosecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationMicro), "1:22:33.111222", `format output with microsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationMilli), "1:22:33.111", `format output with millisecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationNoSubsecond), "1:22:33", `format output with no subsecond digits and fractionalDigits: undefined using ${style} style option`); + +assert.sameValue(df.format(durationFiveFractional), "2:30:11122", `format output with five subsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationSevenFractional), "2:30:1112203", `format output with seven subsecond digits and fractionalDigits: undefined using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js new file mode 100644 index 0000000000..d75f51b14a --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js @@ -0,0 +1,50 @@ +// |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-partitiondurationformatpattern +description: > + Test to ensure that correct number of fractional digits is displayed if fractionalDigits is explicitly specified. + +info: | + 4. If durationFormat.[[FractionalDigits]] is undefined, then + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", 0). + 5. Else, + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). +features: [Intl.DurationFormat] +---*/ + +const duration = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222, + nanoseconds: 333, +}; + + +const style = "digital"; +const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: 0}); +const dfMilli = new Intl.DurationFormat(undefined, {style, fractionalDigits: 3}); +const dfFourDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 4}); +const dfMicro = new Intl.DurationFormat(undefined, {style, fractionalDigits: 6}); +const dfEightDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 8}); +const dfNano = new Intl.DurationFormat(undefined, {style, fractionalDigits: 9}); + +assert.sameValue(df.format(duration), "1:22:33", `format output without sub-second digits using ${style} style option`); + +assert.sameValue(dfMilli.format(duration), "1:22:33.111", `format output with sub-second digits and fractionalDigits: 3 using ${style} style option`); + +assert.sameValue(dfFourDigits.format(duration), "1:22:33.1112", `format output with sub-second digits and fractionalDigits: 4 using ${style} style option`); + +assert.sameValue(dfMicro.format(duration), "1:22:33.111222", `format output with sub-second digits and fractionalDigits: 6 using ${style} style option`); + +assert.sameValue(dfEightDigits.format(duration), "1:22:33.11122233", `format output with sub-second digits and fractionalDigits: 8 using ${style} style option`); + +assert.sameValue(dfNano.format(duration), "1:22:33.111222333", `format output with sub-second digits and fractionalDigits: 9 using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js new file mode 100644 index 0000000000..d9e6fc6cbb --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-long-en.js @@ -0,0 +1,33 @@ +// |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.format +description: Test if format method formats duration correctly with different "style" arguments +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "long"; + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js new file mode 100644 index 0000000000..66b2258761 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-narrow-en.js @@ -0,0 +1,33 @@ +// |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.format +description: Test if format method formats duration correctly with different "style" arguments +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "narrow"; + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js new file mode 100644 index 0000000000..2a66c01b06 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-short-en.js @@ -0,0 +1,33 @@ +// |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.format +description: Test if format method formats duration correctly with different "style" arguments +locale: [en-US] +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +const style = "short"; + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + +const expected = formatDurationFormatPattern(duration, style); + +const df = new Intl.DurationFormat("en", {style}); +assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js new file mode 100644 index 0000000000..1e59d7c6d9 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/throw-invoked-as-func.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.format +description: basic tests internal slot initialization and call receiver errors +info: | + Intl.DurationFormat.prototype.format ( duration ) + (...) + 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). +features: [Intl.DurationFormat] +---*/ + +const df = new Intl.DurationFormat(); + +let f = df["format"]; + +assert.sameValue(typeof f, "function"); +assert.throws(TypeError, () => { + f({ hours: 1, minutes: 46, seconds: 40 }); +}); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/prototype_attributes.js b/js/src/tests/test262/intl402/DurationFormat/prototype/prototype_attributes.js new file mode 100644 index 0000000000..34e2511dda --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/prototype_attributes.js @@ -0,0 +1,21 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright (C) 2021 Nikhil Singhal. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype +description: Prototype attributes verification +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +features: [Intl.DurationFormat] +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.DurationFormat, "prototype", { + value: Intl.DurationFormat.prototype, + writable: false, + enumerable: false, + configurable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/length.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/length.js new file mode 100644 index 0000000000..f59ec0500f --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/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.DurationFormat.prototype.resolvedoptions +description: > + Intl.DurationFormat.prototype.resolvedOptions.length is 0. +info: | + Intl.DurationFormat.prototype.resolvedOptions () + + 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.DurationFormat.prototype.resolvedOptions.length, 0); + +verifyProperty(Intl.DurationFormat.prototype.resolvedOptions, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/name.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/name.js new file mode 100644 index 0000000000..dbab5aaa2b --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/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.resolvedOptions +description: Checks the "name" property of Intl.DurationFormat.prototype.resolvedOptions(). +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.resolvedOptions, "name", { + value: "resolvedOptions", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/prop-desc.js new file mode 100644 index 0000000000..1b667908c4 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/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.resolvedOptions +description: Property descriptor of Intl.DurationFormat.prototype.resolvedOptions +includes: [propertyHelper.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue( + typeof Intl.DurationFormat.prototype.resolvedOptions, + 'function', + '`typeof Intl.DurationFormat.prototype.resolvedOptions` is `function`' +); + +verifyProperty(Intl.DurationFormat.prototype, 'resolvedOptions', { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/shell.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/throw-invoked-as-func.js b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/throw-invoked-as-func.js new file mode 100644 index 0000000000..a75c9f2bb4 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/resolvedOptions/throw-invoked-as-func.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.resolvedOptions +description: basic tests internal slot initialization and call receiver errors +info: | + Intl.DurationFormat.prototype.resolvedOptions ( ) + (...) + 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). +features: [Intl.DurationFormat] +---*/ + +const df = new Intl.DurationFormat(); + +// Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). +let f = df['resolvedOptions']; + +assert.sameValue(typeof f, 'function'); +assert.throws(TypeError, () => { f() }); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/shell.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/browser.js b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/shell.js b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/shell.js diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toString.js b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toString.js new file mode 100644 index 0000000000..b02fe53967 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toString.js @@ -0,0 +1,20 @@ +// |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-@@tostringtag +description: > + Object.prototype.toString utilizes Intl.DurationFormat.prototype[@@toStringTag]. +info: | + Intl.DurationFormat.prototype [ @@toStringTag ] + + The initial value of the @@toStringTag property is the string value "Intl.DurationFormat". + +features: [Intl.DurationFormat, Symbol.toStringTag] +---*/ + +assert.sameValue(Object.prototype.toString.call(Intl.DurationFormat.prototype), "[object Intl.DurationFormat]"); +assert.sameValue(Object.prototype.toString.call(new Intl.DurationFormat()), "[object Intl.DurationFormat]"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toStringTag.js b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toStringTag.js new file mode 100644 index 0000000000..f8cd2882d2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/toStringTag/toStringTag.js @@ -0,0 +1,28 @@ +// |reftest| skip -- Intl.DurationFormat is not supported +// Copyright (C) 2021 Nikhil Singhal. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +// Copyright 2022 Igalia, S.L. All rights reserved. + +/*--- +esid: sec-intl.DurationFormat.prototype-@@tostringtag +description: > + Property descriptor of Intl.DurationFormat.prototype[@@toStringTag]. +info: | + Intl.DurationFormat.prototype [ @@toStringTag ] + + The initial value of the @@toStringTag property is the string value "Intl.DurationFormat". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + +features: [Intl.DurationFormat, Symbol.toStringTag] +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.DurationFormat.prototype, Symbol.toStringTag, { + value: "Intl.DurationFormat", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); |