Intl.RelativeTimeFormat: Add some more tests for supportedLocalesOf.

This commit is contained in:
Ms2ger 2018-08-16 15:13:09 +02:00
parent 60b9467630
commit 867b1ab87d
5 changed files with 141 additions and 0 deletions

View File

@ -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));
}

View File

@ -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`);
}

View File

@ -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");

View File

@ -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)}`);
}

View File

@ -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");