Intl.ListFormat: Add some basic tests for CanonicalizeLocaleList.

This commit is contained in:
Ms2ger 2018-10-15 15:33:57 +02:00 committed by Rick Waldron
parent a3d91b12e5
commit e1d80f75c7
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// 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 various cases for the locales argument to the ListFormat constructor.
info: |
InitializeListFormat (listFormat, locales, options)
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
includes: [testIntl.js]
features: [Intl.ListFormat]
---*/
const defaultLocale = new Intl.ListFormat().resolvedOptions().locale;
const tests = [
[undefined, defaultLocale, "undefined"],
["EN", "en", "Single value"],
[[], defaultLocale, "Empty array"],
[["en-GB-oed"], "en-GB", "Grandfathered"],
[["x-private"], defaultLocale, "Private"],
[["en", "EN"], "en", "Duplicate value (canonical first)"],
[["EN", "en"], "en", "Duplicate value (canonical last)"],
[{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
[{ 0: "DE", length: 1 }, "de", "Object with length"],
];
for (const [locales, expected, name] of tests) {
const rtf = new Intl.ListFormat(locales);
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
}