initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled

This commit is contained in:
2025-09-16 20:46:46 -04:00
commit 9d30169a8d
13378 changed files with 7050105 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
/**************************************************************************/
/* test_fuzzy_search.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/string/fuzzy_search.h"
#include "tests/test_macros.h"
namespace TestFuzzySearch {
struct FuzzySearchTestCase {
String query;
String expected;
};
// Ideally each of these test queries should represent a different aspect, and potentially bottleneck, of the search process.
const FuzzySearchTestCase test_cases[] = {
// Short query, many matches, few adjacent characters
{ "///gd", "./menu/hud/hud.gd" },
// Filename match with typo
{ "sm.png", "./entity/blood_sword/sam.png" },
// Multipart filename word matches
{ "ham ", "./entity/game_trap/ha_missed_me.wav" },
// Single word token matches
{ "push background", "./entity/background_zone1/background/push.png" },
// Long token matches
{ "background_freighter background png", "./entity/background_freighter/background/background.png" },
// Many matches, many short tokens
{ "menu menu characters wav", "./menu/menu/characters/smoker/0.wav" },
// Maximize total matches
{ "entity gd", "./entity/entity_man.gd" }
};
Vector<String> load_test_data() {
Ref<FileAccess> fp = FileAccess::open(TestUtils::get_data_path("fuzzy_search/project_dir_tree.txt"), FileAccess::READ);
REQUIRE(fp.is_valid());
return fp->get_as_utf8_string().split("\n");
}
TEST_CASE("[FuzzySearch] Test fuzzy search results") {
FuzzySearch search;
Vector<FuzzySearchResult> results;
Vector<String> targets = load_test_data();
for (FuzzySearchTestCase test_case : test_cases) {
search.set_query(test_case.query);
search.search_all(targets, results);
CHECK_GT(results.size(), 0);
CHECK_EQ(results[0].target, test_case.expected);
}
}
} //namespace TestFuzzySearch

View File

@@ -0,0 +1,225 @@
/**************************************************************************/
/* test_node_path.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/string/node_path.h"
#include "tests/test_macros.h"
namespace TestNodePath {
TEST_CASE("[NodePath] Relative path") {
const NodePath node_path_relative = NodePath("Path2D/PathFollow2D/Sprite2D:position:x");
CHECK_MESSAGE(
node_path_relative.get_as_property_path() == NodePath(":Path2D/PathFollow2D/Sprite2D:position:x"),
"The returned property path should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_concatenated_subnames() == "position:x",
"The returned concatenated subnames should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_name(0) == "Path2D",
"The returned name at index 0 should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_name(1) == "PathFollow2D",
"The returned name at index 1 should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_name(2) == "Sprite2D",
"The returned name at index 2 should match the expected value.");
ERR_PRINT_OFF;
CHECK_MESSAGE(
node_path_relative.get_name(3) == "",
"The returned name at invalid index 3 should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_name(-1) == "",
"The returned name at invalid index -1 should match the expected value.");
ERR_PRINT_ON;
CHECK_MESSAGE(
node_path_relative.get_name_count() == 3,
"The returned number of names should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_subname(0) == "position",
"The returned subname at index 0 should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_subname(1) == "x",
"The returned subname at index 1 should match the expected value.");
ERR_PRINT_OFF;
CHECK_MESSAGE(
node_path_relative.get_subname(2) == "",
"The returned subname at invalid index 2 should match the expected value.");
CHECK_MESSAGE(
node_path_relative.get_subname(-1) == "",
"The returned subname at invalid index -1 should match the expected value.");
ERR_PRINT_ON;
CHECK_MESSAGE(
node_path_relative.get_subname_count() == 2,
"The returned number of subnames should match the expected value.");
CHECK_MESSAGE(
!node_path_relative.is_absolute(),
"The node path should be considered relative.");
CHECK_MESSAGE(
!node_path_relative.is_empty(),
"The node path shouldn't be considered empty.");
}
TEST_CASE("[NodePath] Absolute path") {
const NodePath node_path_absolute = NodePath("/root/Sprite2D");
CHECK_MESSAGE(
node_path_absolute.get_as_property_path() == NodePath(":root/Sprite2D"),
"The returned property path should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.get_concatenated_subnames() == "",
"The returned concatenated subnames should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.get_name(0) == "root",
"The returned name at index 0 should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.get_name(1) == "Sprite2D",
"The returned name at index 1 should match the expected value.");
ERR_PRINT_OFF;
CHECK_MESSAGE(
node_path_absolute.get_name(2) == "",
"The returned name at invalid index 2 should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.get_name(-1) == "",
"The returned name at invalid index -1 should match the expected value.");
ERR_PRINT_ON;
CHECK_MESSAGE(
node_path_absolute.get_name_count() == 2,
"The returned number of names should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.get_subname_count() == 0,
"The returned number of subnames should match the expected value.");
CHECK_MESSAGE(
node_path_absolute.is_absolute(),
"The node path should be considered absolute.");
CHECK_MESSAGE(
!node_path_absolute.is_empty(),
"The node path shouldn't be considered empty.");
}
TEST_CASE("[NodePath] Empty path") {
const NodePath node_path_empty = NodePath();
CHECK_MESSAGE(
node_path_empty.get_as_property_path() == NodePath(),
"The returned property path should match the expected value.");
ERR_PRINT_OFF;
CHECK_MESSAGE(
node_path_empty.get_concatenated_subnames() == "",
"The returned concatenated subnames should match the expected value.");
ERR_PRINT_ON;
CHECK_MESSAGE(
node_path_empty.get_name_count() == 0,
"The returned number of names should match the expected value.");
CHECK_MESSAGE(
node_path_empty.get_subname_count() == 0,
"The returned number of subnames should match the expected value.");
CHECK_MESSAGE(
!node_path_empty.is_absolute(),
"The node path shouldn't be considered absolute.");
CHECK_MESSAGE(
node_path_empty.is_empty(),
"The node path should be considered empty.");
}
TEST_CASE("[NodePath] Slice") {
const NodePath node_path_relative = NodePath("Parent/Child:prop:subprop");
const NodePath node_path_absolute = NodePath("/root/Parent/Child:prop");
CHECK_MESSAGE(
node_path_relative.slice(0, 2) == NodePath("Parent/Child"),
"The slice lower bound should be inclusive and the slice upper bound should be exclusive.");
CHECK_MESSAGE(
node_path_relative.slice(3) == NodePath(":subprop"),
"Slicing on the last index (length - 1) should return the last entry.");
CHECK_MESSAGE(
node_path_relative.slice(1) == NodePath("Child:prop:subprop"),
"Slicing without upper bound should return remaining entries after index.");
CHECK_MESSAGE(
node_path_relative.slice(1, 3) == NodePath("Child:prop"),
"Slicing should include names and subnames.");
CHECK_MESSAGE(
node_path_relative.slice(-1) == NodePath(":subprop"),
"Slicing on -1 should return the last entry.");
CHECK_MESSAGE(
node_path_relative.slice(0, -1) == NodePath("Parent/Child:prop"),
"Slicing up to -1 should include the second-to-last entry.");
CHECK_MESSAGE(
node_path_relative.slice(-2, -1) == NodePath(":prop"),
"Slicing from negative to negative should treat lower bound as inclusive and upper bound as exclusive.");
CHECK_MESSAGE(
node_path_relative.slice(0, 10) == NodePath("Parent/Child:prop:subprop"),
"Slicing past the length of the path should work like slicing up to the last entry.");
CHECK_MESSAGE(
node_path_relative.slice(-10, 2) == NodePath("Parent/Child"),
"Slicing negatively past the length of the path should work like slicing from the first entry.");
CHECK_MESSAGE(
node_path_relative.slice(1, 1) == NodePath(""),
"Slicing with a lower bound equal to upper bound should return empty path.");
CHECK_MESSAGE(
node_path_absolute.slice(0, 2) == NodePath("/root/Parent"),
"Slice from beginning of an absolute path should be an absolute path.");
CHECK_MESSAGE(
node_path_absolute.slice(1, 4) == NodePath("Parent/Child:prop"),
"Slice of an absolute path that does not start at the beginning should be a relative path.");
CHECK_MESSAGE(
node_path_absolute.slice(3, 4) == NodePath(":prop"),
"Slice of an absolute path that does not start at the beginning should be a relative path.");
CHECK_MESSAGE(
NodePath("").slice(0, 1) == NodePath(""),
"Slice of an empty path should be an empty path.");
CHECK_MESSAGE(
NodePath("").slice(-1, 2) == NodePath(""),
"Slice of an empty path should be an empty path.");
CHECK_MESSAGE(
NodePath("/").slice(-1, 2) == NodePath("/"),
"Slice of an empty absolute path should be an empty absolute path.");
}
} // namespace TestNodePath

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,202 @@
/**************************************************************************/
/* test_translation.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/string/optimized_translation.h"
#include "core/string/translation.h"
#include "core/string/translation_po.h"
#include "core/string/translation_server.h"
#ifdef TOOLS_ENABLED
#include "editor/import/resource_importer_csv_translation.h"
#endif
#include "tests/test_macros.h"
#include "tests/test_utils.h"
namespace TestTranslation {
TEST_CASE("[Translation] Messages") {
Ref<Translation> translation = memnew(Translation);
translation->set_locale("fr");
translation->add_message("Hello", "Bonjour");
CHECK(translation->get_message("Hello") == "Bonjour");
translation->erase_message("Hello");
// The message no longer exists, so it returns an empty string instead.
CHECK(translation->get_message("Hello") == "");
List<StringName> messages;
translation->get_message_list(&messages);
CHECK(translation->get_message_count() == 0);
CHECK(messages.size() == 0);
translation->add_message("Hello2", "Bonjour2");
translation->add_message("Hello3", "Bonjour3");
messages.clear();
translation->get_message_list(&messages);
CHECK(translation->get_message_count() == 2);
CHECK(messages.size() == 2);
// Messages are stored in a Map, don't assume ordering.
CHECK(messages.find("Hello2"));
CHECK(messages.find("Hello3"));
}
TEST_CASE("[TranslationPO] Messages with context") {
Ref<TranslationPO> translation = memnew(TranslationPO);
translation->set_locale("fr");
translation->add_message("Hello", "Bonjour");
translation->add_message("Hello", "Salut", "friendly");
CHECK(translation->get_message("Hello") == "Bonjour");
CHECK(translation->get_message("Hello", "friendly") == "Salut");
CHECK(translation->get_message("Hello", "nonexistent_context") == "");
// Only remove the message for the default context, not the "friendly" context.
translation->erase_message("Hello");
// The message no longer exists, so it returns an empty string instead.
CHECK(translation->get_message("Hello") == "");
CHECK(translation->get_message("Hello", "friendly") == "Salut");
CHECK(translation->get_message("Hello", "nonexistent_context") == "");
List<StringName> messages;
translation->get_message_list(&messages);
// `get_message_count()` takes all contexts into account.
CHECK(translation->get_message_count() == 1);
// Only the default context is taken into account.
// Since "Hello" is now only present in a non-default context, it is not counted in the list of messages.
CHECK(messages.size() == 0);
translation->add_message("Hello2", "Bonjour2");
translation->add_message("Hello2", "Salut2", "friendly");
translation->add_message("Hello3", "Bonjour3");
messages.clear();
translation->get_message_list(&messages);
// `get_message_count()` takes all contexts into account.
CHECK(translation->get_message_count() == 4);
// Only the default context is taken into account.
CHECK(messages.size() == 2);
// Messages are stored in a Map, don't assume ordering.
CHECK(messages.find("Hello2"));
CHECK(messages.find("Hello3"));
}
TEST_CASE("[TranslationPO] Plural messages") {
Ref<TranslationPO> translation = memnew(TranslationPO);
translation->set_locale("fr");
translation->set_plural_rule("Plural-Forms: nplurals=2; plural=(n >= 2);");
CHECK(translation->get_plural_forms() == 2);
PackedStringArray plurals;
plurals.push_back("Il y a %d pomme");
plurals.push_back("Il y a %d pommes");
translation->add_plural_message("There are %d apples", plurals);
ERR_PRINT_OFF;
// This is invalid, as the number passed to `get_plural_message()` may not be negative.
CHECK(vformat(translation->get_plural_message("There are %d apples", "", -1), -1) == "");
ERR_PRINT_ON;
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 0), 0) == "Il y a 0 pomme");
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 1), 1) == "Il y a 1 pomme");
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 2), 2) == "Il y a 2 pommes");
}
#ifdef TOOLS_ENABLED
TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages") {
Ref<Translation> translation = memnew(Translation);
translation->set_locale("fr");
translation->add_message("Hello", "Bonjour");
translation->add_message("Hello2", "Bonjour2");
translation->add_message("Hello3", "Bonjour3");
Ref<OptimizedTranslation> optimized_translation = memnew(OptimizedTranslation);
optimized_translation->generate(translation);
CHECK(optimized_translation->get_message("Hello") == "Bonjour");
CHECK(optimized_translation->get_message("Hello2") == "Bonjour2");
CHECK(optimized_translation->get_message("Hello3") == "Bonjour3");
CHECK(optimized_translation->get_message("DoesNotExist") == "");
List<StringName> messages;
// `get_message_list()` can't return the list of messages stored in an OptimizedTranslation.
optimized_translation->get_message_list(&messages);
CHECK(optimized_translation->get_message_count() == 0);
CHECK(messages.size() == 0);
}
TEST_CASE("[TranslationCSV] CSV import") {
Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation);
HashMap<StringName, Variant> options;
options["compress"] = false;
options["delimiter"] = 0;
List<String> gen_files;
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);
TranslationServer *ts = TranslationServer::get_singleton();
for (const String &file : gen_files) {
Ref<Translation> translation = ResourceLoader::load(file);
CHECK(translation.is_valid());
ts->add_translation(translation);
}
ts->set_locale("en");
// `tr` can be called on any Object, we reuse TranslationServer for convenience.
CHECK(ts->tr("GOOD_MORNING") == "Good Morning");
CHECK(ts->tr("GOOD_EVENING") == "Good Evening");
ts->set_locale("de");
CHECK(ts->tr("GOOD_MORNING") == "Guten Morgen");
CHECK(ts->tr("GOOD_EVENING") == "Good Evening"); // Left blank in CSV, should source from 'en'.
ts->set_locale("ja");
CHECK(ts->tr("GOOD_MORNING") == String::utf8("おはよう"));
CHECK(ts->tr("GOOD_EVENING") == String::utf8("こんばんは"));
/* FIXME: This passes, but triggers a chain reaction that makes test_viewport
* and test_text_edit explode in a billion glittery Unicode particles.
ts->set_locale("fa");
CHECK(ts->tr("GOOD_MORNING") == String::utf8("صبح بخیر"));
CHECK(ts->tr("GOOD_EVENING") == String::utf8("عصر بخیر"));
*/
}
#endif // TOOLS_ENABLED
} // namespace TestTranslation

View File

@@ -0,0 +1,223 @@
/**************************************************************************/
/* test_translation_server.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/string/translation_server.h"
#include "tests/test_macros.h"
namespace TestTranslationServer {
TEST_CASE("[TranslationServer] Translation operations") {
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(t1);
int l_count_after = ts->get_loaded_locales().size();
CHECK(l_count_after > l_count_before);
// 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(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");
}
TEST_CASE("[TranslationServer] Locale operations") {
TranslationServer *ts = TranslationServer::get_singleton();
// Language variant test; we supplied the variant of Español and the result should be the same string.
String loc = "es_Hani_ES_tradnl";
String res = ts->standardize_locale(loc);
CHECK(res == loc);
// No such variant in variant_map; should return everything except the variant.
loc = "es_Hani_ES_missing";
res = ts->standardize_locale(loc);
CHECK(res == "es_Hani_ES");
// Non-ISO language name check (Windows issue).
loc = "iw_Hani_IL";
res = ts->standardize_locale(loc);
CHECK(res == "he_Hani_IL");
// Country rename check.
loc = "uk_Hani_UK";
res = ts->standardize_locale(loc);
CHECK(res == "uk_Hani_GB");
// Supplying a script name that is not in the list.
loc = "de_Wrong_DE";
res = ts->standardize_locale(loc);
CHECK(res == "de_DE");
// No added defaults.
loc = "es_ES";
res = ts->standardize_locale(loc, true);
CHECK(res == "es_ES");
// Add default script.
loc = "az_AZ";
res = ts->standardize_locale(loc, true);
CHECK(res == "az_Latn_AZ");
// Add default country.
loc = "pa_Arab";
res = ts->standardize_locale(loc, true);
CHECK(res == "pa_Arab_PK");
// Add default script and country.
loc = "zh";
res = ts->standardize_locale(loc, true);
CHECK(res == "zh_Hans_CN");
// Explicitly don't add defaults.
loc = "zh";
res = ts->standardize_locale(loc, false);
CHECK(res == "zh");
}
TEST_CASE("[TranslationServer] Comparing locales") {
TranslationServer *ts = TranslationServer::get_singleton();
String locale_a = "es";
String locale_b = "es";
// Exact match check.
int res = ts->compare_locales(locale_a, locale_b);
CHECK(res == 10);
locale_a = "sr-Latn-CS";
locale_b = "sr-Latn-RS";
// Script matches (+1) but country doesn't (-1).
res = ts->compare_locales(locale_a, locale_b);
CHECK(res == 5);
locale_a = "uz-Cyrl-UZ";
locale_b = "uz-Latn-UZ";
// 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 == 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";
// No match.
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