summaryrefslogtreecommitdiff
path: root/Tests/LibLocale
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-13 10:28:16 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-13 18:22:04 +0200
commit0b69e9f974ff023029e89b1fca3529a1c5b62d71 (patch)
treef8475121e8c2d66b394d5ea04b7e712018c33cfa /Tests/LibLocale
parent259a84b7b68dc61dc6bd98c4b562f7eb1ed74542 (diff)
downloadserenity-0b69e9f974ff023029e89b1fca3529a1c5b62d71.zip
LibLocale: Prepare locale data generator for breaking changes in CLDR 43
In CLDR 42 and earlier, we were able to assume all cldr-localename files existed for every locale. They now do not exist for locales that don't provide any localized data. Namely, this is the "und" locale (which is an alias for the root locale, i.e. the locale we fall back to when a user provides an unknown locale). Further, we were previously able to assume that each currencies.json in cldr-numbers contained all currencies. This file now excludes currencies whose localized names are the same as the currency key. Therefore, we now preprocess currencies.json to discover all currencies ahead of time, much like we already do for languages.json.
Diffstat (limited to 'Tests/LibLocale')
-rw-r--r--Tests/LibLocale/TestLocale.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/Tests/LibLocale/TestLocale.cpp b/Tests/LibLocale/TestLocale.cpp
index 7300faddac..754a819698 100644
--- a/Tests/LibLocale/TestLocale.cpp
+++ b/Tests/LibLocale/TestLocale.cpp
@@ -518,3 +518,75 @@ TEST_CASE(supports_locale_aliases)
EXPECT(Locale::is_locale_available("zh-TW"sv));
EXPECT(Locale::is_locale_available("zh-Hant-TW"sv));
}
+
+TEST_CASE(locale_mappings_en)
+{
+ auto language = Locale::get_locale_language_mapping("en"sv, "en"sv);
+ EXPECT(language.has_value());
+ EXPECT_EQ(*language, "English"sv);
+
+ language = Locale::get_locale_language_mapping("en"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!language.has_value());
+
+ auto territory = Locale::get_locale_territory_mapping("en"sv, "US"sv);
+ EXPECT(territory.has_value());
+ EXPECT_EQ(*territory, "United States"sv);
+
+ territory = Locale::get_locale_territory_mapping("en"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!territory.has_value());
+
+ auto script = Locale::get_locale_script_mapping("en"sv, "Latn"sv);
+ EXPECT(script.has_value());
+ EXPECT_EQ(*script, "Latin"sv);
+
+ script = Locale::get_locale_script_mapping("en"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!script.has_value());
+}
+
+TEST_CASE(locale_mappings_fr)
+{
+ auto language = Locale::get_locale_language_mapping("fr"sv, "en"sv);
+ EXPECT(language.has_value());
+ EXPECT_EQ(*language, "anglais"sv);
+
+ language = Locale::get_locale_language_mapping("fr"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!language.has_value());
+
+ auto territory = Locale::get_locale_territory_mapping("fr"sv, "US"sv);
+ EXPECT(territory.has_value());
+ EXPECT_EQ(*territory, "ร‰tats-Unis"sv);
+
+ territory = Locale::get_locale_territory_mapping("fr"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!territory.has_value());
+
+ auto script = Locale::get_locale_script_mapping("fr"sv, "Latn"sv);
+ EXPECT(script.has_value());
+ EXPECT_EQ(*script, "latin"sv);
+
+ script = Locale::get_locale_script_mapping("fr"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!script.has_value());
+}
+
+TEST_CASE(locale_mappings_root)
+{
+ auto language = Locale::get_locale_language_mapping("und"sv, "en"sv);
+ EXPECT(language.has_value());
+ EXPECT_EQ(*language, "en"sv);
+
+ language = Locale::get_locale_language_mapping("und"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!language.has_value());
+
+ auto territory = Locale::get_locale_territory_mapping("und"sv, "US"sv);
+ EXPECT(territory.has_value());
+ EXPECT_EQ(*territory, "US"sv);
+
+ territory = Locale::get_locale_territory_mapping("und"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!territory.has_value());
+
+ auto script = Locale::get_locale_script_mapping("und"sv, "Latn"sv);
+ EXPECT(script.has_value());
+ EXPECT_EQ(*script, "Latn"sv);
+
+ script = Locale::get_locale_script_mapping("und"sv, "i-defintely-don't-exist"sv);
+ EXPECT(!script.has_value());
+}