summaryrefslogtreecommitdiffstats
path: root/tests/core/string
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core/string')
-rw-r--r--tests/core/string/test_translation.h2
-rw-r--r--tests/core/string/test_translation_server.h88
2 files changed, 75 insertions, 15 deletions
diff --git a/tests/core/string/test_translation.h b/tests/core/string/test_translation.h
index 7c389191e3..2b1069d40c 100644
--- a/tests/core/string/test_translation.h
+++ b/tests/core/string/test_translation.h
@@ -161,7 +161,7 @@ TEST_CASE("[TranslationCSV] CSV import") {
List<String> gen_files;
- Error result = import_csv_translation->import(TestUtils::get_data_path("translations.csv"),
+ Error result = import_csv_translation->import(0, TestUtils::get_data_path("translations.csv"),
"", options, nullptr, &gen_files);
CHECK(result == OK);
CHECK(gen_files.size() == 4);
diff --git a/tests/core/string/test_translation_server.h b/tests/core/string/test_translation_server.h
index ac1599f2e8..6668a7b57b 100644
--- a/tests/core/string/test_translation_server.h
+++ b/tests/core/string/test_translation_server.h
@@ -37,27 +37,37 @@
namespace TestTranslationServer {
TEST_CASE("[TranslationServer] Translation operations") {
- Ref<Translation> t = memnew(Translation);
- t->set_locale("uk");
- t->add_message("Good Morning", String::utf8("Добрий ранок"));
+ Ref<Translation> t1 = memnew(Translation);
+ t1->set_locale("uk");
+ t1->add_message("Good Morning", String(U"Добрий ранок"));
+
+ Ref<Translation> t2 = memnew(Translation);
+ t2->set_locale("uk");
+ t2->add_message("Hello Godot", String(U"你好戈多"));
TranslationServer *ts = TranslationServer::get_singleton();
+ // Adds translation for UK locale for the first time.
int l_count_before = ts->get_loaded_locales().size();
- ts->add_translation(t);
+ ts->add_translation(t1);
int l_count_after = ts->get_loaded_locales().size();
- // Newly created Translation object should be added to the list, so the counter should increase, too.
CHECK(l_count_after > l_count_before);
- Ref<Translation> trans = ts->get_translation_object("uk");
- CHECK(trans.is_valid());
+ // Adds translation for UK locale again.
+ ts->add_translation(t2);
+ CHECK_EQ(ts->get_loaded_locales().size(), l_count_after);
+
+ // Removing that translation.
+ ts->remove_translation(t2);
+ CHECK_EQ(ts->get_loaded_locales().size(), l_count_after);
+
+ CHECK(ts->get_translation_object("uk").is_valid());
ts->set_locale("uk");
CHECK(ts->translate("Good Morning") == String::utf8("Добрий ранок"));
- ts->remove_translation(t);
- trans = ts->get_translation_object("uk");
- CHECK(trans.is_null());
+ ts->remove_translation(t1);
+ CHECK(ts->get_translation_object("uk").is_null());
// If no suitable Translation object has been found - the original message should be returned.
CHECK(ts->translate("Good Morning") == "Good Morning");
}
@@ -110,18 +120,50 @@ TEST_CASE("[TranslationServer] Comparing locales") {
locale_a = "sr-Latn-CS";
locale_b = "sr-Latn-RS";
- // Two elements from locales match.
+ // Script matches (+1) but country doesn't (-1).
res = ts->compare_locales(locale_a, locale_b);
- CHECK(res == 2);
+ CHECK(res == 5);
locale_a = "uz-Cyrl-UZ";
locale_b = "uz-Latn-UZ";
- // Two elements match, but they are not sequentual.
+ // Country matches (+1) but script doesn't (-1).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 5);
+
+ locale_a = "aa-Latn-ER";
+ locale_b = "aa-Latn-ER-saaho";
+
+ // Script and country match (+2) with variant on one locale (+0).
res = ts->compare_locales(locale_a, locale_b);
- CHECK(res == 2);
+ CHECK(res == 7);
+
+ locale_a = "uz-Cyrl-UZ";
+ locale_b = "uz-Latn-KG";
+
+ // Both script and country mismatched (-2).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 3);
+
+ locale_a = "es-ES";
+ locale_b = "es-AR";
+
+ // Mismatched country (-1).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 4);
+
+ locale_a = "es";
+ locale_b = "es-AR";
+
+ // No country for one locale (+0).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 5);
locale_a = "es-EC";
locale_b = "fr-LU";
@@ -130,6 +172,24 @@ TEST_CASE("[TranslationServer] Comparing locales") {
res = ts->compare_locales(locale_a, locale_b);
CHECK(res == 0);
+
+ locale_a = "zh-HK";
+ locale_b = "zh";
+
+ // In full standardization, zh-HK becomes zh_Hant_HK and zh becomes
+ // zh_Hans_CN. Both script and country mismatch (-2).
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 3);
+
+ locale_a = "zh-CN";
+ locale_b = "zh";
+
+ // In full standardization, zh and zh-CN both become zh_Hans_CN for an
+ // exact match.
+ res = ts->compare_locales(locale_a, locale_b);
+
+ CHECK(res == 10);
}
} // namespace TestTranslationServer