summaryrefslogtreecommitdiffstats
path: root/tests/core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/config/test_project_settings.h2
-rw-r--r--tests/core/math/test_aabb.h2
-rw-r--r--tests/core/math/test_color.h2
-rw-r--r--tests/core/math/test_rect2.h2
-rw-r--r--tests/core/object/test_object.h4
-rw-r--r--tests/core/string/test_fuzzy_search.h83
-rw-r--r--tests/core/string/test_string.h43
-rw-r--r--tests/core/string/test_translation.h2
-rw-r--r--tests/core/variant/test_variant_utility.h2
9 files changed, 122 insertions, 20 deletions
diff --git a/tests/core/config/test_project_settings.h b/tests/core/config/test_project_settings.h
index 0e1058a626..5a000b19a0 100644
--- a/tests/core/config/test_project_settings.h
+++ b/tests/core/config/test_project_settings.h
@@ -40,7 +40,7 @@ class TestProjectSettingsInternalsAccessor {
public:
static String &resource_path() {
return ProjectSettings::get_singleton()->resource_path;
- };
+ }
};
namespace TestProjectSettings {
diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h
index 741e6af5d4..eb6977fd69 100644
--- a/tests/core/math/test_aabb.h
+++ b/tests/core/math/test_aabb.h
@@ -48,7 +48,7 @@ TEST_CASE("[AABB] Constructor methods") {
TEST_CASE("[AABB] String conversion") {
CHECK_MESSAGE(
- String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2, -2.5), S: (4, 5, 6)]",
+ String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2.0, -2.5), S: (4.0, 5.0, 6.0)]",
"The string representation should match the expected value.");
}
diff --git a/tests/core/math/test_color.h b/tests/core/math/test_color.h
index bd2d4f40e5..3d36079102 100644
--- a/tests/core/math/test_color.h
+++ b/tests/core/math/test_color.h
@@ -140,7 +140,7 @@ TEST_CASE("[Color] Conversion methods") {
cyan.to_rgba64() == 0x0000'ffff'ffff'ffff,
"The returned 64-bit BGR number should match the expected value.");
CHECK_MESSAGE(
- String(cyan) == "(0, 1, 1, 1)",
+ String(cyan) == "(0.0, 1.0, 1.0, 1.0)",
"The string representation should match the expected value.");
}
diff --git a/tests/core/math/test_rect2.h b/tests/core/math/test_rect2.h
index c4368808a6..a93bfeb71b 100644
--- a/tests/core/math/test_rect2.h
+++ b/tests/core/math/test_rect2.h
@@ -57,7 +57,7 @@ TEST_CASE("[Rect2] Constructor methods") {
TEST_CASE("[Rect2] String conversion") {
// Note: This also depends on the Vector2 string representation.
CHECK_MESSAGE(
- String(Rect2(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]",
+ String(Rect2(0, 100, 1280, 720)) == "[P: (0.0, 100.0), S: (1280.0, 720.0)]",
"The string representation should match the expected value.");
}
diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h
index e703698ec6..55c53e2d03 100644
--- a/tests/core/object/test_object.h
+++ b/tests/core/object/test_object.h
@@ -95,10 +95,10 @@ public:
}
bool property_can_revert(const StringName &p_name) const override {
return false;
- };
+ }
bool property_get_revert(const StringName &p_name, Variant &r_ret) const override {
return false;
- };
+ }
void get_method_list(List<MethodInfo> *p_list) const override {
}
bool has_method(const StringName &p_method) const override {
diff --git a/tests/core/string/test_fuzzy_search.h b/tests/core/string/test_fuzzy_search.h
new file mode 100644
index 0000000000..d647ebdd1a
--- /dev/null
+++ b/tests/core/string/test_fuzzy_search.h
@@ -0,0 +1,83 @@
+/**************************************************************************/
+/* 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. */
+/**************************************************************************/
+
+#ifndef TEST_FUZZY_SEARCH_H
+#define TEST_FUZZY_SEARCH_H
+
+#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
+
+#endif // TEST_FUZZY_SEARCH_H
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index 8d6137cf62..9adc97e845 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -389,6 +389,19 @@ TEST_CASE("[String] Find") {
MULTICHECK_STRING_INT_EQ(s, rfind, "", 15, -1);
}
+TEST_CASE("[String] Find character") {
+ String s = "racecar";
+ CHECK_EQ(s.find_char('r'), 0);
+ CHECK_EQ(s.find_char('r', 1), 6);
+ CHECK_EQ(s.find_char('e'), 3);
+ CHECK_EQ(s.find_char('e', 4), -1);
+
+ CHECK_EQ(s.rfind_char('r'), 6);
+ CHECK_EQ(s.rfind_char('r', 5), 0);
+ CHECK_EQ(s.rfind_char('e'), 3);
+ CHECK_EQ(s.rfind_char('e', 2), -1);
+}
+
TEST_CASE("[String] Find case insensitive") {
String s = "Pretty Whale Whale";
MULTICHECK_STRING_EQ(s, findn, "WHA", 7);
@@ -455,9 +468,9 @@ TEST_CASE("[String] Erasing") {
}
TEST_CASE("[String] Number to string") {
- CHECK(String::num(0) == "0");
- CHECK(String::num(0.0) == "0"); // No trailing zeros.
- CHECK(String::num(-0.0) == "-0"); // Includes sign even for zero.
+ CHECK(String::num(0) == "0.0"); // The method takes double, so always add zeros.
+ CHECK(String::num(0.0) == "0.0");
+ CHECK(String::num(-0.0) == "-0.0"); // Includes sign even for zero.
CHECK(String::num(3.141593) == "3.141593");
CHECK(String::num(3.141593, 3) == "3.142");
CHECK(String::num(42.100023, 4) == "42.1"); // No trailing zeros.
@@ -492,15 +505,15 @@ TEST_CASE("[String] Number to string") {
CHECK(String::num_real(3.141593) == "3.141593");
CHECK(String::num_real(3.141) == "3.141"); // No trailing zeros.
#ifdef REAL_T_IS_DOUBLE
- CHECK_MESSAGE(String::num_real(123.456789) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
- CHECK_MESSAGE(String::num_real(-123.456789) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
- CHECK_MESSAGE(String::num_real(Math_PI) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
- CHECK_MESSAGE(String::num_real(3.1415f) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
+ CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
+ CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
+ CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
+ CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
#else
- CHECK_MESSAGE(String::num_real(123.456789) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
- CHECK_MESSAGE(String::num_real(-123.456789) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
- CHECK_MESSAGE(String::num_real(Math_PI) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
- CHECK_MESSAGE(String::num_real(3.1415f) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
+ CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
+ CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
+ CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
+ CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
#endif // REAL_T_IS_DOUBLE
// Checks doubles with many decimal places.
@@ -509,7 +522,7 @@ TEST_CASE("[String] Number to string") {
CHECK(String::num(-0.0000012345432123454321) == "-0.00000123454321");
CHECK(String::num(-10000.0000012345432123454321) == "-10000.0000012345");
CHECK(String::num(0.0000000000012345432123454321) == "0.00000000000123");
- CHECK(String::num(0.0000000000012345432123454321, 3) == "0");
+ CHECK(String::num(0.0000000000012345432123454321, 3) == "0.0");
// Note: When relevant (remainder > 0.5), the last digit gets rounded up,
// which can also lead to not include a trailing zero, e.g. "...89" -> "...9".
@@ -1254,6 +1267,12 @@ TEST_CASE("[String] is_subsequence_of") {
CHECK(String("Sub").is_subsequence_ofn(a));
}
+TEST_CASE("[String] is_lowercase") {
+ CHECK(String("abcd1234 !@#$%^&*()_-=+,.<>/\\|[]{};':\"`~").is_lowercase());
+ CHECK(String("").is_lowercase());
+ CHECK(!String("abc_ABC").is_lowercase());
+}
+
TEST_CASE("[String] match") {
CHECK(String("img1.png").match("*.png"));
CHECK(!String("img1.jpeg").match("*.png"));
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/variant/test_variant_utility.h b/tests/core/variant/test_variant_utility.h
index 93458b63f4..34b4880d51 100644
--- a/tests/core/variant/test_variant_utility.h
+++ b/tests/core/variant/test_variant_utility.h
@@ -89,7 +89,7 @@ TEST_CASE("[VariantUtility] Type conversion") {
converted = VariantUtilityFunctions::type_convert(basis, Variant::Type::STRING);
CHECK(converted.get_type() == Variant::Type::STRING);
- CHECK(converted == Variant("[X: (1.2, 0, 0), Y: (0, 3.4, 0), Z: (0, 0, 5.6)]"));
+ CHECK(converted == Variant("[X: (1.2, 0.0, 0.0), Y: (0.0, 3.4, 0.0), Z: (0.0, 0.0, 5.6)]"));
}
{