diff --git a/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/locales-invalid.js b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/locales-invalid.js new file mode 100644 index 0000000000..3964ba9018 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/locales-invalid.js @@ -0,0 +1,20 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.supportedLocalesOf +description: Checks error cases for the locales argument to the supportedLocalesOf function. +info: | + Intl.RelativeTimeFormat.supportedLocalesOf ( locales [, options ]) + + 2. Let requestedLocales be CanonicalizeLocaleList(locales). +includes: [testIntl.js] +features: [Intl.RelativeTimeFormat] +---*/ + +assert.sameValue(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function", + "Should support Intl.RelativeTimeFormat.supportedLocalesOf."); + +for (const [locales, expectedError] of getInvalidLocaleArguments()) { + assert.throws(expectedError, () => Intl.RelativeTimeFormat.supportedLocalesOf(locales)); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-localeMatcher-invalid.js b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-localeMatcher-invalid.js new file mode 100644 index 0000000000..a1bd71689b --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-localeMatcher-invalid.js @@ -0,0 +1,34 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.supportedLocalesOf +description: Checks handling of invalid values for the localeMatcher option to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + b. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.RelativeTimeFormat] +---*/ + +assert.sameValue(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function", + "Should support Intl.RelativeTimeFormat.supportedLocalesOf."); + +const invalidOptions = [ + null, + 1, + "", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + Intl.RelativeTimeFormat.supportedLocalesOf([], {"localeMatcher": invalidOption}); + }, `${invalidOption} is an invalid localeMatcher option value`); +} diff --git a/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-null.js b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-null.js new file mode 100644 index 0000000000..807e9f9aff --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-null.js @@ -0,0 +1,20 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.supportedLocalesOf +description: Checks handling of a null options argument to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + a. Let options be ? ToObject(options). +features: [Intl.RelativeTimeFormat] +---*/ + +assert.sameValue(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function", + "Should support Intl.RelativeTimeFormat.supportedLocalesOf."); + +assert.throws(TypeError, function() { + Intl.RelativeTimeFormat.supportedLocalesOf([], null); +}, "Should throw when passing null as the options argument"); diff --git a/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-toobject.js b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-toobject.js new file mode 100644 index 0000000000..2f87db4eff --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-toobject.js @@ -0,0 +1,41 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.supportedLocalesOf +description: Checks handling of non-object options arguments to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + a. Let options be ? ToObject(options). +features: [Intl.RelativeTimeFormat] +---*/ + +assert.sameValue(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function", + "Should support Intl.RelativeTimeFormat.supportedLocalesOf."); + +let called; +Object.defineProperties(Object.prototype, { + "localeMatcher": { + get() { + ++called; + return "best fit"; + } + } +}); + +const optionsArguments = [ + true, + "test", + 7, + Symbol(), +]; + +for (const options of optionsArguments) { + called = 0; + const result = Intl.RelativeTimeFormat.supportedLocalesOf([], options); + assert.sameValue(Array.isArray(result), true, `Expected array from ${String(options)}`); + assert.sameValue(called, 1, `Expected one call from ${String(options)}`); +} + diff --git a/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-undefined.js b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-undefined.js new file mode 100644 index 0000000000..1a995eae64 --- /dev/null +++ b/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/options-undefined.js @@ -0,0 +1,26 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.RelativeTimeFormat.supportedLocalesOf +description: Checks handling of an undefined options argument to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + b. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.RelativeTimeFormat] +---*/ + +assert.sameValue(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function", + "Should support Intl.RelativeTimeFormat.supportedLocalesOf."); + +Object.defineProperties(Object.prototype, { + "localeMatcher": { + get() { throw new Error("Should not call localeMatcher getter"); } + } +}); + +assert.sameValue(Array.isArray(Intl.RelativeTimeFormat.supportedLocalesOf()), true, "No arguments"); +assert.sameValue(Array.isArray(Intl.RelativeTimeFormat.supportedLocalesOf([])), true, "One argument"); +assert.sameValue(Array.isArray(Intl.RelativeTimeFormat.supportedLocalesOf([], undefined)), true, "Two arguments");