diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/intl402/DurationFormat | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/DurationFormat')
71 files changed, 1706 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/DurationFormat/browser.js b/js/src/tests/test262/intl402/DurationFormat/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-locales-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-locales-invalid.js new file mode 100644 index 0000000000..687ae01c37 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-locales-invalid.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 +description: Checks error cases for the locales argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 3. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +for (const [locales, expectedError] of getInvalidLocaleArguments()) { + assert.throws(expectedError, function() { new Intl.DurationFormat(locales) }) +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-locales-valid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-locales-valid.js new file mode 100644 index 0000000000..6d58367d43 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-locales-valid.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 +description: Checks cases for the locales argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 3. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). +features: [Intl.DurationFormat] +---*/ + +const defaultLocale = new Intl.DurationFormat().resolvedOptions().locale; + +const matchers = ["lookup", "best fit"] + +const tests = [ + [undefined, defaultLocale, "undefined"], + ["EN", "en", "Single value"], + [[], defaultLocale, "Empty array"], + [["en", "EN"], "en", "Duplicate value (canonical first)"], + [["EN", "en"], "en", "Duplicate value (canonical last)"], + [{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"], + [{ 0: "DE", length: 1 }, "de", "Object with length"], +]; + + +for (const [locales, expected, name] of tests) { + matchers.forEach((matcher)=>{ + const drf = new Intl.DurationFormat(locales, {localeMatcher: matcher}); + assert.sameValue(drf.resolvedOptions().locale, expected, name); + }); +}; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-defaults.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-defaults.js new file mode 100644 index 0000000000..90c8c62a28 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-defaults.js @@ -0,0 +1,36 @@ +// |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: Checks handling of valid options for the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 17. For each row in Table 1, except the header row, in table order, do + a. Let styleSlot be the Style Slot value. + b. Let displaySlot be the Display Slot value. + c. Let unit be the Unit value. + d. Let valueList be the Values value. + e. Let digitalBase be the Digital Default value. + f. Let unitOptions be ? GetUnitOptions(unit, options, style, valueList, digitalBase, prevStyle). + g. Set durationFormat.[[<styleSlot>]] to unitOptions.[[Style]]. + h. Set durationFormat.[[<displaySlot>]] to unitOptions.[[Display]]. +features: [Intl.DurationFormat] +includes: [testIntl.js] +---*/ + +testOption( Intl.DurationFormat, "years", "string", ["long", "short", "narrow"], "short"); +testOption( Intl.DurationFormat, "months", "string", ["long", "short", "narrow"], "short"); +testOption( Intl.DurationFormat, "weeks", "string", ["long", "short", "narrow"], "short"); +testOption( Intl.DurationFormat, "days", "string", ["long", "short", "narrow"], "short"); +testOption( Intl.DurationFormat, "hours", "string", ["long", "short", "narrow", "numeric", "2-digit"], "short"); +testOption( Intl.DurationFormat, "minutes", "string", ["long", "short", "narrow", "numeric", "2-digit"], "short"); +testOption( Intl.DurationFormat, "seconds", "string", ["long", "short", "narrow", "numeric", "2-digit"], "short"); +testOption( Intl.DurationFormat, "milliseconds", "string", ["long", "short", "narrow", "numeric"], "short"); +testOption( Intl.DurationFormat, "microseconds", "string", ["long", "short", "narrow", "numeric"], "short"); +testOption( Intl.DurationFormat, "nanoseconds", "string", ["long", "short", "narrow", "numeric"], "short"); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-invalid.js new file mode 100644 index 0000000000..7f580a8e32 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-invalid.js @@ -0,0 +1,26 @@ +// |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: Tests that the option localeMatcher is processed correctly. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 18. Set durationFormat.[[FractionalDigits]] to ? GetNumberOption(options, "fractionalDigits", 0, 9, undefined). +features: [Intl.DurationFormat] +---*/ + +const invalidOptions = [ + -10, + 10 +]; + +for (const fractionalDigits of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.DurationFormat("en", { fractionalDigits }); + }, `new Intl.DurationFormat("en", {fractionalDigits: "${fractionalDigits}"}) throws RangeError`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js new file mode 100644 index 0000000000..cc97748d60 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js @@ -0,0 +1,27 @@ +// |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: Tests that the option localeMatcher is processed correctly. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 18. Set durationFormat.[[FractionalDigits]] to ? GetNumberOption(options, "fractionalDigits", 0, 9, undefined). +features: [Intl.DurationFormat] +---*/ + +const validOptions = [ + 0, + 1, + 5, + 9 +]; + +for (const fractionalDigits of validOptions) { + const obj = new Intl.DurationFormat("en", {fractionalDigits}); + assert.sameValue(obj.resolvedOptions().fractionalDigits, fractionalDigits, `${fractionalDigits} is supported by DurationFormat`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-invalid.js new file mode 100644 index 0000000000..26b0c361fa --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-invalid.js @@ -0,0 +1,19 @@ +// |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: Checks handling of a null options argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 4. Let options be GetOptionsObject(options). +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat, "function"); + +assert.throws(TypeError, function() { new Intl.DurationFormat([], null) }) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-invalid.js new file mode 100644 index 0000000000..ed89c0787f --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-invalid.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 +description: Checks handling of invalid value for the localeMatcher option to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). +features: [Intl.DurationFormat] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const localeMatcher of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.DurationFormat([], { localeMatcher }); + }, `${localeMatcher} is an invalid localeMatcher option value`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-valid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-valid.js new file mode 100644 index 0000000000..0190aabe73 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-localeMatcher-valid.js @@ -0,0 +1,18 @@ +// |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: Tests that the option localeMatcher is processed correctly. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). +features: [Intl.DurationFormat] +includes: [testIntl.js] +---*/ + +testOption(Intl.DurationFormat, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-invalid.js new file mode 100644 index 0000000000..eac66df308 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-invalid.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 +description: > + Checks error cases for the options argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). + 7. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. +features: [Intl.DurationFormat] +---*/ + +const invalidOptions = [ + "", + "a", + "ab", + "abcdefghi", + "abc-abcdefghi", + "!invalid!", + "-latn-", + "latn-", + "latn--", + "latn-ca", + "latn-ca-", + "latn-ca-gregory", + "latné", + "latn编号", +]; +for (const numberingSystem of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.DurationFormat('en', {numberingSystem}); + }, `new Intl.DurationFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-valid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-valid.js new file mode 100644 index 0000000000..c053bba51a --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-numberingSystem-valid.js @@ -0,0 +1,24 @@ +// |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: > + Checks error cases for the options argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). + 7. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. +features: [Intl.DurationFormat] +---*/ + +const numberingSystems = Intl.supportedValuesOf("numberingSystem"); + +for (const numberingSystem of numberingSystems) { + const obj = new Intl.DurationFormat("en", {numberingSystem}); + assert.sameValue(obj.resolvedOptions().numberingSystem, numberingSystem, `${numberingSystem} is supported by DurationFormat`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-order.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-order.js new file mode 100644 index 0000000000..073a62fb5c --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-order.js @@ -0,0 +1,44 @@ +// |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: Checks the order of operations on the options argument to the DurationFormat constructor. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). + 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). +includes: [compareArray.js] +features: [Intl.DurationFormat] +---*/ + +var actual = []; + +const options = { + get localeMatcher() { + actual.push("localeMatcher"); + return undefined; + }, + get numberingSystem() { + actual.push("numberingSystem"); + return undefined; + }, + get style() { + actual.push("style"); + return undefined; + }, +}; + +const expected = [ + "localeMatcher", + "numberingSystem", + "style" +]; + +let nf = new Intl.DurationFormat(undefined, options); +assert.compareArray(actual, expected); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-invalid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-invalid.js new file mode 100644 index 0000000000..7b8bcced9d --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-invalid.js @@ -0,0 +1,40 @@ +// |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: Checks handling of invalid value for the style option to the DurationFormat constructor. +info: | + InitializeDurationFormat (DurationFormat, locales, options) + (...) + 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). + 14. Set durationFormat.[[Style]] to style. +features: [Intl.DurationFormat] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Long", + "LONG", + "long\0", + "Short", + "SHORT", + "short\0", + "Narrow", + "NARROW", + "narrow\0", + "Digital", + "DIGITAL", + "digital\0", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.DurationFormat([], {"style": invalidOption}); + }, `${invalidOption} is an invalid style option value`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-valid.js b/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-valid.js new file mode 100644 index 0000000000..03ebfe4d2d --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/constructor-options-style-valid.js @@ -0,0 +1,34 @@ +// |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: Checks handling of valid values for the style option to the DurationFormat constructor. +info: | + InitializeDurationFormat (DurationFormat, locales, options) + (...) + 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "short"). + 14. Set durationFormat.[[Style]] to style. +features: [Intl.DurationFormat] +---*/ + +const validOptions = [ + [undefined, "short"], + ["long", "long"], + ["short", "short"], + ["narrow", "narrow"], + ["digital", "digital"], + [{ toString() { return "short"; } }, "short"], + [{ toString() { return "long"; } }, "long"], + [{ toString() { return "narrow"; } }, "narrow"], + [{ toString() { return "digital"; } }, "digital"], +]; + +for (const [validOption, expected] of validOptions) { + const df = new Intl.DurationFormat([], {"style": validOption}); + const resolvedOptions = df.resolvedOptions(); + assert.sameValue(resolvedOptions.style, expected); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/extensibility.js b/js/src/tests/test262/intl402/DurationFormat/extensibility.js new file mode 100644 index 0000000000..f0d7dcc554 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/extensibility.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 +description: Intl.DurationFormat instance object extensibility +info: | + 17 ECMAScript Standard Built-in Objects: + + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. + +features: [Intl.DurationFormat] +---*/ + +assert.sameValue( + Object.isExtensible(new Intl.DurationFormat()), + true, + "Object.isExtensible(new Intl.DurationFormat()) returns true" +); + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/length.js b/js/src/tests/test262/intl402/DurationFormat/length.js new file mode 100644 index 0000000000..f59faedd88 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/length.js @@ -0,0 +1,36 @@ +// |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: > + Intl.DurationFormat.length is 0. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + + 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, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/name.js b/js/src/tests/test262/intl402/DurationFormat/name.js new file mode 100644 index 0000000000..1dd1d72c2d --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/name.js @@ -0,0 +1,32 @@ +// |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: > + Intl.DurationFormat.name is "DurationFormat". +info: | + Intl.DurationFormat ([ locales [ , options ]]) + + 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 }. + +features: [Intl.DurationFormat] +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.DurationFormat, 'name', { + value: 'DurationFormat', + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/newtarget-undefined.js b/js/src/tests/test262/intl402/DurationFormat/newtarget-undefined.js new file mode 100644 index 0000000000..5cafac6772 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/newtarget-undefined.js @@ -0,0 +1,30 @@ +// |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: > + Verifies the NewTarget check for Intl.DurationFormat. +info: | + Intl.DurationFormat ([ locales [ , options ]]) + (...) + 1. If NewTarget is undefined, throw a TypeError exception. +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat, "function"); + +assert.throws(TypeError, function() { + Intl.DurationFormat(); +}); + +assert.throws(TypeError, function() { + Intl.DurationFormat("en"); +}); + +assert.throws(TypeError, function() { + Intl.DurationFormat("not-valid-tag"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/prop-desc.js new file mode 100644 index 0000000000..4f5ad92f25 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/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: > + "DurationFormat" property of Intl. +info: | + Intl.DurationFormat ([ locales [ , options ]]) + + 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', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/prototype.js b/js/src/tests/test262/intl402/DurationFormat/prototype.js new file mode 100644 index 0000000000..69ba3ef085 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype.js @@ -0,0 +1,23 @@ +// |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: Intl.DurationFormat instance object is created from %DurationFormatPrototype%. +info: | + Intl.DurationFormat ([ locales [ , options ]]) + + 2. Let durationFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%DurationFormatPrototype%", « [[InitializedDurationFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[YearsStyle]], [[YearsDisplay]], [[MonthsStyle]], [[MonthsDisplay]] , [[WeeksStyle]], [[WeeksDisplay]] , [[DaysStyle]], [[DaysDisplay]] , [[HoursStyle]], [[HoursDisplay]] , [[MinutesStyle]], [[MinutesDisplay]] , [[SecondsStyle]], [[SecondsDisplay]] , [[MillisecondsStyle]], [[MillisecondsDisplay]] , [[MicrosecondsStyle]], [[MicrosecondsDisplay]] , [[NanosecondsStyle]], [[NanosecondsDisplay]], [[FractionalDigits]] »). + +features: [Intl.DurationFormat] +---*/ + +const value = new Intl.DurationFormat(); +assert.sameValue( + Object.getPrototypeOf(value), + Intl.DurationFormat.prototype, + "Object.getPrototypeOf(value) equals the value of Intl.DurationFormat.prototype" +); + +reportCompare(0, 0); 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..70187debfc --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/constructor/prop-desc.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 +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] +---*/ + +verifyNotEnumerable(Intl.DurationFormat.prototype, "constructor"); +verifyWritable(Intl.DurationFormat.prototype, "constructor"); +verifyConfigurable(Intl.DurationFormat.prototype, "constructor"); + +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/basic-format-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/basic-format-en.js new file mode 100644 index 0000000000..5425a54770 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/basic-format-en.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: Test if format method formats duration correctly +locale: [en-US] +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 df = new Intl.DurationFormat('en'); + +assert.sameValue(df.format(duration), "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns"); + +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/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/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-options-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-options-en.js new file mode 100644 index 0000000000..69c9268688 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/format/style-options-en.js @@ -0,0 +1,40 @@ +// |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] +features: [Intl.DurationFormat] +---*/ + +const testData = { + "long" : "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, 9 nanoseconds", + "short": "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns", + "narrow":"1y 2m 3w 3d 4h 5m 6s 7ms 8μs 9ns", + "digital":"1 yr 2 mths 3 wks 3 days 4:05:06", +} + +const duration = { + years: 1, + months: 2, + weeks: 3, + days: 3, + hours: 4, + minutes: 5, + seconds: 6, + milliseconds: 7, + microseconds: 8, + nanoseconds: 9, +}; + + +for (const style in testData) { + const df = new Intl.DurationFormat("en", {style}); + const expected = testData[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-styles-en.js b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-styles-en.js new file mode 100644 index 0000000000..1389724f50 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/formatToParts/formatToParts-styles-en.js @@ -0,0 +1,125 @@ +// |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. +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 testsData = { + short: [ + { type: "integer", value: "7", unit: "hour" }, + { type: "literal", value: " ", unit: "hour" }, + { type: "unit", value: "hr", unit: "hour" }, + { type: "literal", value: ", " }, + { type: "integer", value: "8", unit: "minute" }, + { type: "literal", value: " ", unit: "minute" }, + { type: "unit", value: "min", unit: "minute" }, + { type: "literal", value: ", " }, + { type: "integer", value: "9", unit: "second" }, + { type: "literal", value: " ", unit: "second" }, + { type: "unit", value: "sec", unit: "second" }, + { type: "literal", value: ", " }, + { type: "integer", value: "123", unit: "millisecond" }, + { type: "literal", value: " ", unit: "millisecond" }, + { type: "unit", value: "msec", unit: "millisecond" }, + { type: "literal", value: ", " }, + { type: "integer", value: "456", unit: "microsecond" }, + { type: "literal", value: " ", unit: "microsecond" }, + { type: "unit", value: "μsec", unit: "microsecond" }, + { type: "literal", value: " and " }, + { type: "integer", value: "789", unit: "nanosecond" }, + { type: "literal", value: " ", unit: "nanosecond" }, + { type: "unit", value: "nsec", unit: "nanosecond" }, + ], + long: [ + { type: "integer", value: "7", unit: "hour" }, + { type: "literal", value: " ", unit: "hour" }, + { type: "unit", value: "hours", unit: "hour" }, + { type: "literal", value: ", " }, + { type: "integer", value: "8", unit: "minute" }, + { type: "literal", value: " ", unit: "minute" }, + { type: "unit", value: "minutes", unit: "minute" }, + { type: "literal", value: ", " }, + { type: "integer", value: "9", unit: "second" }, + { type: "literal", value: " ", unit: "second" }, + { type: "unit", value: "seconds", unit: "second" }, + { type: "literal", value: ", " }, + { type: "integer", value: "123", unit: "millisecond" }, + { type: "literal", value: " ", unit: "millisecond" }, + { type: "unit", value: "milliseconds", unit: "millisecond" }, + { type: "literal", value: ", " }, + { type: "integer", value: "456", unit: "microsecond" }, + { type: "literal", value: " ", unit: "microsecond" }, + { type: "unit", value: "microseconds", unit: "microsecond" }, + { type: "literal", value: " and " }, + { type: "integer", value: "789", unit: "nanosecond" }, + { type: "literal", value: " ", unit: "nanosecond" }, + { type: "unit", value: "nanoseconds", unit: "nanosecond" }, + ], + narrow: [ + { type: "integer", value: "7", unit: "hour" }, + { type: "unit", value: "h", unit: "hour" }, + { type: "literal", value: " " }, + { type: "integer", value: "8", unit: "minute" }, + { type: "unit", value: "m", unit: "minute" }, + { type: "literal", value: " " }, + { type: "integer", value: "9", unit: "second" }, + { type: "unit", value: "s", unit: "second" }, + { type: "literal", value: " " }, + { type: "integer", value: "123", unit: "millisecond" }, + { type: "unit", value: "ms", unit: "millisecond" }, + { type: "literal", value: " " }, + { type: "integer", value: "456", unit: "microsecond" }, + { type: "unit", value: "μs", unit: "microsecond" }, + { type: "literal", value: " " }, + { type: "integer", value: "789", unit: "nanosecond" }, + { type: "unit", value: "ns", unit: "nanosecond" }, + ], + digital: [ + { type: "integer", value: "7", unit: "hour" }, + { type: "literal", value: ":", unit: "hour" }, + { type: "integer", value: "08", unit: "minute" }, + { type: "literal", value: ":", unit: "minute" }, + { type: "integer", value: "09", unit: "second" }, + ], +}; + +for (const style in testsData) { + let df = new Intl.DurationFormat('en', { style }); + compare(df.formatToParts(duration), testsData[style], `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/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..459541e7cd --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/prototype/prototype_attributes.js @@ -0,0 +1,18 @@ +// |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] +---*/ + +verifyNotEnumerable(Intl.DurationFormat, "prototype"); +verifyNotWritable(Intl.DurationFormat, "prototype"); +verifyNotConfigurable(Intl.DurationFormat, "prototype"); + +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); diff --git a/js/src/tests/test262/intl402/DurationFormat/shell.js b/js/src/tests/test262/intl402/DurationFormat/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/shell.js diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/basic.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/basic.js new file mode 100644 index 0000000000..300e1d24ee --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/basic.js @@ -0,0 +1,22 @@ +// |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.supportedLocalesOf +description: Tests that Intl.DurationFormat has a supportedLocalesOf property, and it works as expected. +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat.supportedLocalesOf, "function", + "supportedLocalesOf should be supported."); + +const defaultLocale = new Intl.DurationFormat().resolvedOptions().locale; +const notSupported = "zxx"; // "no linguistic content" +const requestedLocales = [defaultLocale, notSupported]; + +const supportedLocales = Intl.DurationFormat.supportedLocalesOf(requestedLocales); +assert.sameValue(supportedLocales.length, 1, "The length of the supported locales list should be 1"); +assert.sameValue(supportedLocales[0], defaultLocale, "The default locale is returned in the supported list."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/branding.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/branding.js new file mode 100644 index 0000000000..d8ab61d338 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/branding.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.supportedLocalesOf +description: > + Verifies there's no branding check for Intl.DurationFormat.supportedLocalesOf(). +info: | + Intl.DurationFormat.supportedLocalesOf ( locales [, options ]) +features: [Intl.DurationFormat] +---*/ + +const supportedLocalesOf = Intl.DurationFormat.supportedLocalesOf; + +assert.sameValue(typeof supportedLocalesOf, "function"); + +const thisValues = [ + undefined, + null, + true, + "", + Symbol(), + 1, + {}, + Intl.DurationFormat, + Intl.DurationFormat.prototype, +]; + +for (const thisValue of thisValues) { + const result = supportedLocalesOf.call(thisValue); + assert.sameValue(Array.isArray(result), true); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/browser.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/browser.js diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/length.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/length.js new file mode 100644 index 0000000000..b3c6b3e1d2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/length.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.supportedLocalesOf +description: > + Checks the "length" property of Intl.DurationFormat.supportedLocalesOf(). +info: | + The value of the length property of the supportedLocalesOf method is 1. + 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 2019 Language Specification, 10th edition, clause 17, or successor. + Every built-in function object, including constructors, has a length property whose value is an integer. + Unless otherwise specified, the length property of a built-in function object has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DurationFormat] +---*/ + +verifyProperty(Intl.DurationFormat.supportedLocalesOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-empty.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-empty.js new file mode 100644 index 0000000000..14fc1b0494 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-empty.js @@ -0,0 +1,22 @@ +// |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.supportedLocalesOf +description: Checks handling of an empty locales argument to the supportedLocalesOf function. +info: | + Intl.DurationFormat.supportedLocalesOf ( locales [, options ]) + (...) + 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). +includes: [compareArray.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat.supportedLocalesOf, "function", + "Should support Intl.DurationFormat.supportedLocalesOf."); + +assert.compareArray(Intl.DurationFormat.supportedLocalesOf(), []); +assert.compareArray(Intl.DurationFormat.supportedLocalesOf([]), []); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-invalid.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-invalid.js new file mode 100644 index 0000000000..8f5e8c0e81 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-invalid.js @@ -0,0 +1,23 @@ +// |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.supportedLocalesOf +description: Checks error cases for the locales argument to the supportedLocalesOf function. +info: | + Intl.DurationFormat.supportedLocalesOf ( locales [, options ]) + (...) + 2. Let requestedLocales be CanonicalizeLocaleList(locales). +includes: [testIntl.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat.supportedLocalesOf, "function", + "Should support Intl.DurationFormat.supportedLocalesOf."); + +for (const [locales, expectedError] of getInvalidLocaleArguments()) { + assert.throws(expectedError, () => Intl.DurationFormat.supportedLocalesOf(locales)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-specific.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-specific.js new file mode 100644 index 0000000000..77696d7ef0 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/locales-specific.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.supportedLocalesOf +description: Checks handling of specific locales arguments to the supportedLocalesOf function. +info: | + Intl.DurationFormat.supportedLocalesOf ( locales [, options ]) + (...) + 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). +includes: [compareArray.js] +locale: [sr, sr-Thai-RS, de, zh-CN] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(typeof Intl.DurationFormat.supportedLocalesOf, "function", + "Should support Intl.DurationFormat.supportedLocalesOf."); + +assert.compareArray(Intl.DurationFormat.supportedLocalesOf("sr"), ["sr"]); + +const multiLocale = ["sr-Thai-RS", "de", "zh-CN"]; +assert.compareArray(Intl.DurationFormat.supportedLocalesOf(multiLocale, {localeMatcher: "lookup"}), multiLocale); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/name.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/name.js new file mode 100644 index 0000000000..dc452628d0 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/name.js @@ -0,0 +1,24 @@ +// |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.supportedLocalesOf +description: > + Checks the "name" property of Intl.DurationFormat.supportedLocalesOf(). +info: | + 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 2019 Language Specification, 10th edition, clause 17, or successor. + 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, this value is the name that is given to the function in this specification. + 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.supportedLocalesOf, "name", { + value: "supportedLocalesOf", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/prop-desc.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/prop-desc.js new file mode 100644 index 0000000000..ff212a9704 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/prop-desc.js @@ -0,0 +1,32 @@ +// |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.supportedLocalesOf +description: > + Checks the "supportedLocalesOf" property of the DurationFormat prototype object. +info: | + Intl.DurationFormat.supportedLocalesOf ( locales [, options ]) + + 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 2019 Language Specification, 10th edition, clause 17, or successor. + + 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. +includes: [propertyHelper.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue( + typeof Intl.DurationFormat.supportedLocalesOf, + "function", + "typeof Intl.DurationFormat.supportedLocalesOf is function" +); + +verifyProperty(Intl.DurationFormat, "supportedLocalesOf", { + writable: true, + enumerable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/shell.js b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/DurationFormat/supportedLocalesOf/shell.js |