diff --git a/test/intl402/DurationFormat/instance/undefined-newtarget-throws.js b/test/intl402/DurationFormat/instance/undefined-newtarget-throws.js new file mode 100644 index 00000000000..45da879e300 --- /dev/null +++ b/test/intl402/DurationFormat/instance/undefined-newtarget-throws.js @@ -0,0 +1,24 @@ +// 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: > + Throws a TypeError if Intl.DurationFormat is called as a function. +info: | + Intl.DurationFormat ([ locales [ , options ]]) + 1. If NewTarget is undefined, throw a TypeError exception. +features: [Intl.DurationFormat] +---*/ + +assert.throws(TypeError, function() { + Intl.DurationFormat(); +}); + +assert.throws(TypeError, function() { + Intl.DurationFormat('en'); +}); + +assert.throws(TypeError, function() { + Intl.DurationFormat(['en']); +}); diff --git a/test/intl402/DurationFormat/prototype/constructor/options-localeMatcher-invalid.js b/test/intl402/DurationFormat/prototype/constructor/options-localeMatcher-invalid.js new file mode 100644 index 00000000000..3e59a34de9d --- /dev/null +++ b/test/intl402/DurationFormat/prototype/constructor/options-localeMatcher-invalid.js @@ -0,0 +1,36 @@ +// 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 when using invalid localeMatcher. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). +features: [Intl.DurationFormat] +---*/ + +const invalidLocaleMatcherOptions = [ + null, + 1, + "", + "001", + "latn--", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const localeMatcher of invalidLocaleMatcherOptions) { + assert.throws( + RangeError, + function () { + new Intl.DurationFormat("en", { localeMatcher }); + }, + `new Intl.DurationFormat("en", { localeMatcher: "${localeMatcher}"}) throws RangeError` + ); +} diff --git a/test/intl402/DurationFormat/prototype/constructor/options-numberingSystem-invalid.js b/test/intl402/DurationFormat/prototype/constructor/options-numberingSystem-invalid.js new file mode 100644 index 00000000000..c12ea7b4568 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/constructor/options-numberingSystem-invalid.js @@ -0,0 +1,41 @@ +// 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 when using invalid numberingSystem. +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 invalidNumberingSystemOptions = [ + "", + "a", + "ab", + "abcdefghi", + "abc-abcdefghi", + "!invalid!", + "-latn-", + "latn-", + "latn--", + "latn-ca", + "latn-ca-", + "latn-ca-gregory", + "latné", + "latn编号", +]; + +for (const numberingSystem of invalidNumberingSystemOptions) { + assert.throws( + RangeError, + function () { + new Intl.DurationFormat("en", { numberingSystem }); + }, + `new Intl.DurationFormat("en", {numberingSystem: "${numberingSystem}"}) throws RangeError` + ); +} diff --git a/test/intl402/DurationFormat/prototype/constructor/options-style-invalid.js b/test/intl402/DurationFormat/prototype/constructor/options-style-invalid.js new file mode 100644 index 00000000000..9adf444da58 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/constructor/options-style-invalid.js @@ -0,0 +1,41 @@ +// 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 when using invalid numberingSystem. +info: | + Intl.DurationFormat ( [ locales [ , options ] ] ) + (...) + 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). +features: [Intl.DurationFormat] +---*/ + +const invalidStyleOptions = [ + null, + 1, + "", + "Long", + "LONG", + "long\0", + "Short", + "SHORT", + "short\0", + "Narrow", + "NARROW", + "narrow\0", + "Digital", + "DIGITAL", + "digital\0", +]; + +for (const style of invalidStyleOptions) { + assert.throws(RangeError, function() { + new Intl.DurationFormat("en", {style}); + }, `new Intl.DurationFormat("en", { style : "${style}"}) throws RangeError`); +} + + + + diff --git a/test/intl402/DurationFormat/prototype/constructor/value.js b/test/intl402/DurationFormat/prototype/constructor/value.js index ba18803e1a8..a82ad77ea5d 100644 --- a/test/intl402/DurationFormat/prototype/constructor/value.js +++ b/test/intl402/DurationFormat/prototype/constructor/value.js @@ -1,4 +1,4 @@ -// Copyright 2012 Google Inc. All rights reserved. +// Copyright 2022 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/test/intl402/DurationFormat/prototype/format/branding.js b/test/intl402/DurationFormat/prototype/format/branding.js new file mode 100644 index 00000000000..66a67d8efd9 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/branding.js @@ -0,0 +1,23 @@ +// 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), "undefined"); +assert.throws(TypeError, () => format.call(null), "null"); +assert.throws(TypeError, () => format.call(true), "true"); +assert.throws(TypeError, () => format.call(""), "empty string"); +assert.throws(TypeError, () => format.call(Symbol()), "symbol"); +assert.throws(TypeError, () => format.call(1), "1"); +assert.throws(TypeError, () => format.call({}), "plain object"); +assert.throws(TypeError, () => format.call(Intl.DurationFormat), "Intl.DurationFormat"); +assert.throws(TypeError, () => format.call(Intl.DurationFormat.prototype), "Intl.DurationFormat.prototype"); + diff --git a/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js b/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js new file mode 100644 index 00000000000..9e49d3ab545 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/invalid-arguments-throws.js @@ -0,0 +1,25 @@ +// 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) +---*/ + +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(Symbol())}, "symbol"); +assert.throws(TypeError, () => { df.format("bad string")}, "bad string"); diff --git a/test/intl402/DurationFormat/prototype/format/invalid-duration-object.throws.js b/test/intl402/DurationFormat/prototype/format/invalid-duration-object.throws.js new file mode 100644 index 00000000000..3209aa2ce06 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/invalid-duration-object.throws.js @@ -0,0 +1,29 @@ +// 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) +---*/ + +const df = new Intl.DurationFormat(); + +assert.throws(RangeError, () => { df.format({ + hours : -1, + minutes: 10 +}), "Throws when mixing negative positive options" }); + +assert.throws(RangeError, () => { df.format({ + hours : 2, + minutes: -10 +}), "Throws when mixing negative positive options" }); + +assert.throws(RangeError, () => { df.format({ + hours : -1, + minutes: 10 +}), "Throws when mixing negative positive options" }); diff --git a/test/intl402/DurationFormat/prototype/format/length.js b/test/intl402/DurationFormat/prototype/format/length.js index 14d71405739..87e92204254 100644 --- a/test/intl402/DurationFormat/prototype/format/length.js +++ b/test/intl402/DurationFormat/prototype/format/length.js @@ -2,9 +2,9 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-intl.datetimeformat.prototype.format +esid: sec-Intl.DurationFormat.prototype.format description: > - Intl.DateTimeFormat.prototype.format.length is 1. + Intl.DurationFormat.prototype.format.length is 1. info: | Intl.DurationFormat.prototype.format ( duration ) @@ -25,7 +25,7 @@ features: [Intl.DurationFormat] includes: [propertyHelper.js] ---*/ -assert.sameValue(Intl.DateTimeFormat.prototype.format.length, 1); +assert.sameValue(Intl.DurationFormat.prototype.format.length, 1); verifyProperty(Intl.DurationFormat.prototype.format, "length", { value: 1, diff --git a/test/intl402/DurationFormat/prototype/format/not-a-constructor.js b/test/intl402/DurationFormat/prototype/format/not-a-constructor.js new file mode 100644 index 00000000000..b5c848c9d60 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/not-a-constructor.js @@ -0,0 +1,21 @@ +// 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)"); diff --git a/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js b/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js index fa075a1f41e..5b9eb18f794 100644 --- a/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js +++ b/test/intl402/DurationFormat/prototype/format/throw-invoked-as-func.js @@ -14,8 +14,9 @@ features: [Intl.DurationFormat] const df = new Intl.DurationFormat(); // Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). -let f = df['format']; - -assert.sameValue(typeof f, 'function'); -assert.throws(TypeError, () => { f('PT12.3456S') }); +let f = df["format"]; +assert.sameValue(typeof f, "function"); +assert.throws(TypeError, () => { + f({ hours: 1, minutes: 46, seconds: 40 }); +}); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/branding.js b/test/intl402/DurationFormat/prototype/formatToParts/branding.js new file mode 100644 index 00000000000..4a6bfdfea67 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/branding.js @@ -0,0 +1,23 @@ +// 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), "undefined"); +assert.throws(TypeError, () => formatToParts.call(null), "null"); +assert.throws(TypeError, () => formatToParts.call(true), "true"); +assert.throws(TypeError, () => formatToParts.call(""), "empty string"); +assert.throws(TypeError, () => formatToParts.call(Symbol()), "symbol"); +assert.throws(TypeError, () => formatToParts.call(1), "1"); +assert.throws(TypeError, () => formatToParts.call({}), "plain object"); +assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat), "Intl.DurationFormat"); +assert.throws(TypeError, () => formatToParts.call(Intl.DurationFormat.prototype), "Intl.DurationFormat.prototype"); + diff --git a/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js b/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js new file mode 100644 index 00000000000..fb781381038 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js @@ -0,0 +1,25 @@ +// 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) +---*/ + +const df = new Intl.DurationFormat(); + +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(Symbol())}, "symbol"); +assert.throws(TypeError, () => { df.formatToParts("bad string")}, "bad string"); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js b/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js index 66af26956c3..8fe60f202b7 100644 --- a/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js +++ b/test/intl402/DurationFormat/prototype/formatToParts/throw-invoked-as-func.js @@ -17,5 +17,6 @@ const df = new Intl.DurationFormat(); let f = df['formatToParts']; assert.sameValue(typeof f, 'function'); -assert.throws(TypeError, () => { f('PT12.3456S') }); - +assert.throws(TypeError, () => { + f({ hours: 1, minutes: 46, seconds: 40 }); +}); diff --git a/test/intl402/DurationFormat/supportedLocalesOf/basic.js b/test/intl402/DurationFormat/supportedLocalesOf/basic.js new file mode 100644 index 00000000000..ade14454df5 --- /dev/null +++ b/test/intl402/DurationFormat/supportedLocalesOf/basic.js @@ -0,0 +1,19 @@ +// 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 supported locales list is not 1.'); +assert.sameValue(supportedLocales[0], defaultLocale, 'The default locale is not returned in the supported list.'); diff --git a/test/intl402/DurationFormat/supportedLocalesOf/branding.js b/test/intl402/DurationFormat/supportedLocalesOf/branding.js new file mode 100644 index 00000000000..613226e9904 --- /dev/null +++ b/test/intl402/DurationFormat/supportedLocalesOf/branding.js @@ -0,0 +1,32 @@ +// 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); +} diff --git a/test/intl402/DurationFormat/supportedLocalesOf/length.js b/test/intl402/DurationFormat/supportedLocalesOf/length.js new file mode 100644 index 00000000000..5f47d5579d0 --- /dev/null +++ b/test/intl402/DurationFormat/supportedLocalesOf/length.js @@ -0,0 +1,19 @@ +// 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(). +includes: [propertyHelper.js] +features: [Intl.DurationFormat] +---*/ + +assert.sameValue(Intl.DateTimeFormat.prototype.format.length, 1); + +verifyProperty(Intl.DurationFormat.supportedLocalesOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/intl402/DurationFormat/supportedLocalesOf/name.js b/test/intl402/DurationFormat/supportedLocalesOf/name.js new file mode 100644 index 00000000000..de7df470fe7 --- /dev/null +++ b/test/intl402/DurationFormat/supportedLocalesOf/name.js @@ -0,0 +1,20 @@ +// 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 +}); diff --git a/test/intl402/DurationFormat/supportedLocalesOf/prop-desc.js b/test/intl402/DurationFormat/supportedLocalesOf/prop-desc.js new file mode 100644 index 00000000000..12408a92971 --- /dev/null +++ b/test/intl402/DurationFormat/supportedLocalesOf/prop-desc.js @@ -0,0 +1,23 @@ +// 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 ]) +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, +}); +