Add more testing of SupportedLocalesOf()

R=gsathya@chromium.org, littledan@chromium.org

Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ib3806f2b8d6f8adf61fe0dc8c327c461e1d20304
Reviewed-on: https://chromium-review.googlesource.com/1095558
Commit-Queue: Brian Stell <bstell@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53653}
This commit is contained in:
Brian Stell 2018-06-11 15:12:24 -07:00 committed by Commit Bot
parent 294dbf49bc
commit b365b641c3

View File

@ -28,10 +28,10 @@
// Tests supportedLocalesOf method. // Tests supportedLocalesOf method.
var undef = Intl.DateTimeFormat.supportedLocalesOf(); var undef = Intl.DateTimeFormat.supportedLocalesOf();
assertEquals(undefined, undef[0]); assertEquals([], undef);
var empty = Intl.DateTimeFormat.supportedLocalesOf([]); var empty = Intl.DateTimeFormat.supportedLocalesOf([]);
assertEquals(undefined, empty[0]); assertEquals([], empty);
var strLocale = Intl.DateTimeFormat.supportedLocalesOf('sr'); var strLocale = Intl.DateTimeFormat.supportedLocalesOf('sr');
assertEquals('sr', strLocale[0]); assertEquals('sr', strLocale[0]);
@ -41,3 +41,41 @@ var multiLocale =
assertEquals('sr-Thai-RS', multiLocale[0]); assertEquals('sr-Thai-RS', multiLocale[0]);
assertEquals('de', multiLocale[1]); assertEquals('de', multiLocale[1]);
assertEquals('zh-CN', multiLocale[2]); assertEquals('zh-CN', multiLocale[2]);
collatorUndef = Intl.Collator.supportedLocalesOf();
assertEquals([], collatorUndef);
collatorEmpty = Intl.Collator.supportedLocalesOf([]);
assertEquals([], collatorEmpty);
collatorStrLocale = Intl.Collator.supportedLocalesOf('sr');
assertEquals('sr', collatorStrLocale[0]);
collatorMultiLocale =
Intl.Collator.supportedLocalesOf(['sr-Thai-RS', 'de', 'zh-CN']);
assertEquals('sr-Thai-RS', collatorMultiLocale[0]);
assertEquals('de', collatorMultiLocale[1]);
assertEquals('zh-CN', collatorMultiLocale[2]);
numLocale = Intl.Collator.supportedLocalesOf(1);
assertEquals([], numLocale);
assertThrows(function() {
numLocale = Intl.Collator.supportedLocalesOf([1]);
}, TypeError);
extensionLocale = Intl.Collator.supportedLocalesOf('id-u-co-pinyin');
assertEquals('id-u-co-pinyin', extensionLocale[0]);
bestFitLocale =
Intl.Collator.supportedLocalesOf('de', {localeMatcher: 'best fit'});
assertEquals('de', bestFitLocale[0]);
// Need a better test for "lookup" once it differs from "best fit".
lookupLocale =
Intl.Collator.supportedLocalesOf('zh-CN', {localeMatcher: 'lookup'});
assertEquals('zh-CN', lookupLocale[0]);
assertThrows(function() {
Intl.Collator.supportedLocalesOf('id-u-co-pinyin', {localeMatcher: 'xyz'});
}, RangeError);