diff options
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat/prototype/format')
24 files changed, 856 insertions, 0 deletions
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); |