Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2091)

Unified Diff: app/l10n_util_unittest.cc

Issue 5643002: Add utility function to determine if a locale is valid syntax; this will... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: app/l10n_util_unittest.cc
===================================================================
--- app/l10n_util_unittest.cc (revision 68844)
+++ app/l10n_util_unittest.cc (working copy)
@@ -322,3 +322,57 @@
result = l10n_util::GetDisplayNameForLocale("es-419", "en", false);
EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)"));
}
+
+TEST_F(L10nUtilTest, IsValidLocaleSyntax) {
+ // Test valid locales.
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("fr"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("de"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("pt"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("fil"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("haw"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en-US"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en_US"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en_GB"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("pt-BR"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh_CN"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh_Hans"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh_Hans_CN"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh_Hant"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zh_Hant_TW"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("fr_CA"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("i-klingon"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("es-021"));
jungshik at Google 2010/12/10 22:21:28 nit: perhaps, 'es-419' (one of languages CHrome is
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en_IE_PREEURO"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("en_IE@currency=IEP"));
jungshik at Google 2010/12/10 22:21:28 would you mind adding en_IE_u_cu_IEP (a newer form
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("fr@x=y"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax("zn_CN@foo=bar"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax(
+ "fr@collation=phonebook;calendar=islamic-civil"));
+ EXPECT_EQ(true, l10n_util::IsValidLocaleSyntax(
+ "sr_Latn_RS_REVISED@currency=USD"));
+
+ // Test invalid locales.
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax(""));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("x"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("12"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("456"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("a1"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("enUS"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("zhcn"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en.US"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en#US"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("-en-US"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en-US-"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("123-en-US"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("Latin"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("German"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("pt--BR"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("sl-macedonia"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("@"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en-US@"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en-US@x"));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en-US@x="));
+ EXPECT_EQ(false, l10n_util::IsValidLocaleSyntax("en-US@=y"));
+}

Powered by Google App Engine
This is Rietveld 408576698