Skip to content
Snippets Groups Projects
Commit f6dcb4fc authored by Ms2ger's avatar Ms2ger Committed by Leo Balter
Browse files

Intl.ListFormat: Add some tests for the localeMatcher constructor option. (#1855)

This was added in https://github.com/tc39/proposal-intl-list-format/pull/25.

I don't know how to test that the option has any effect, so this just checks
that it is read and verified.
parent e654d7b2
No related branches found
No related tags found
No related merge requests found
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.ListFormat
description: Checks handling of invalid value for the localeMatcher option to the ListFormat constructor.
info: |
Intl.ListFormat ( [ locales [ , options ] ] )
12. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
features: [Intl.ListFormat]
---*/
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.ListFormat([], { localeMatcher });
}, `${localeMatcher} is an invalid localeMatcher option value`);
}
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
esid: sec-Intl.ListFormat esid: sec-Intl.ListFormat
description: Checks the order of operations on the options argument to the ListFormat constructor. description: Checks the order of operations on the options argument to the ListFormat constructor.
info: | info: |
InitializeListFormat (listFormat, locales, options) Intl.ListFormat ( [ locales [ , options ] ] )
7. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). 7. Let type be GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
14. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). 9. Let style be GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
16. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always"). 12. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
includes: [compareArray.js] includes: [compareArray.js]
features: [Intl.ListFormat] features: [Intl.ListFormat]
---*/ ---*/
...@@ -16,6 +16,16 @@ features: [Intl.ListFormat] ...@@ -16,6 +16,16 @@ features: [Intl.ListFormat]
const callOrder = []; const callOrder = [];
new Intl.ListFormat([], { new Intl.ListFormat([], {
get localeMatcher() {
callOrder.push("localeMatcher");
return {
toString() {
callOrder.push("localeMatcher toString");
return "best fit";
}
};
},
get type() { get type() {
callOrder.push("type"); callOrder.push("type");
return { return {
...@@ -25,6 +35,7 @@ new Intl.ListFormat([], { ...@@ -25,6 +35,7 @@ new Intl.ListFormat([], {
} }
}; };
}, },
get style() { get style() {
callOrder.push("style"); callOrder.push("style");
return { return {
...@@ -41,4 +52,6 @@ assert.compareArray(callOrder, [ ...@@ -41,4 +52,6 @@ assert.compareArray(callOrder, [
"type toString", "type toString",
"style", "style",
"style toString", "style toString",
"localeMatcher",
"localeMatcher toString",
]); ]);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment