mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Intl.RelativeTimeFormat: Add some more tests for supportedLocalesOf.
This commit is contained in:
parent
60b9467630
commit
867b1ab87d
@ -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));
|
||||||
|
}
|
@ -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`);
|
||||||
|
}
|
@ -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");
|
@ -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)}`);
|
||||||
|
}
|
||||||
|
|
@ -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");
|
Loading…
x
Reference in New Issue
Block a user