From a0dbdcc3abbd3e6307c6e68d0e60f8c0fa31d576 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Mon, 6 May 2024 16:20:20 +0200 Subject: Replace `find` with `contains/has` where applicable * Replaces `find(...) != -1` with `contains` for `String` * Replaces `find(...) == -1` with `!contains` for `String` * Replaces `find(...) != -1` with `has` for containers * Replaces `find(...) == -1` with `!has` for containers --- tests/core/object/test_class_db.h | 12 ++++++------ tests/test_main.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h index fb62d0f056..381d759e5b 100644 --- a/tests/core/object/test_class_db.h +++ b/tests/core/object/test_class_db.h @@ -195,12 +195,12 @@ struct Context { } bool has_type(const TypeReference &p_type_ref) const { - if (builtin_types.find(p_type_ref.name) >= 0) { + if (builtin_types.has(p_type_ref.name)) { return true; } if (p_type_ref.is_enum) { - if (enum_types.find(p_type_ref.name) >= 0) { + if (enum_types.has(p_type_ref.name)) { return true; } @@ -355,7 +355,7 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co const ArgumentData &idx_arg = getter->arguments.front()->get(); if (idx_arg.type.name != p_context.names_cache.int_type) { // If not an int, it can be an enum - TEST_COND(p_context.enum_types.find(idx_arg.type.name) < 0, + TEST_COND(!p_context.enum_types.has(idx_arg.type.name), "Invalid type '", idx_arg.type.name, "' for index argument of property getter: '", p_class.name, ".", String(p_prop.name), "'."); } } @@ -367,7 +367,7 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co if (idx_arg.type.name != p_context.names_cache.int_type) { // Assume the index parameter is an enum // If not an int, it can be an enum - TEST_COND(p_context.enum_types.find(idx_arg.type.name) < 0, + TEST_COND(!p_context.enum_types.has(idx_arg.type.name), "Invalid type '", idx_arg.type.name, "' for index argument of property setter: '", p_class.name, ".", String(p_prop.name), "'."); } } @@ -736,7 +736,7 @@ void add_exposed_classes(Context &r_context) { for (const StringName &E : K.value.constants) { const StringName &constant_name = E; - TEST_FAIL_COND(String(constant_name).find("::") != -1, + TEST_FAIL_COND(String(constant_name).contains("::"), "Enum constant contains '::', check bindings to remove the scope: '", String(class_name), ".", String(enum_.name), ".", String(constant_name), "'."); int64_t *value = class_info->constant_map.getptr(constant_name); @@ -758,7 +758,7 @@ void add_exposed_classes(Context &r_context) { for (const String &E : constants) { const String &constant_name = E; - TEST_FAIL_COND(constant_name.find("::") != -1, + TEST_FAIL_COND(constant_name.contains("::"), "Constant contains '::', check bindings to remove the scope: '", String(class_name), ".", constant_name, "'."); int64_t *value = class_info->constant_map.getptr(StringName(E)); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 69d8113e64..41fc21b469 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -242,7 +242,7 @@ struct GodotTestCaseListener : public doctest::IReporter { String name = String(p_in.m_name); String suite_name = String(p_in.m_test_suite); - if (name.find("[SceneTree]") != -1 || name.find("[Editor]") != -1) { + if (name.contains("[SceneTree]") || name.contains("[Editor]")) { memnew(MessageQueue); memnew(Input); @@ -291,7 +291,7 @@ struct GodotTestCaseListener : public doctest::IReporter { } #ifdef TOOLS_ENABLED - if (name.find("[Editor]") != -1) { + if (name.contains("[Editor]")) { Engine::get_singleton()->set_editor_hint(true); EditorPaths::create(); EditorSettings::create(); @@ -301,7 +301,7 @@ struct GodotTestCaseListener : public doctest::IReporter { return; } - if (name.find("Audio") != -1) { + if (name.contains("Audio")) { // The last driver index should always be the dummy driver. int dummy_idx = AudioDriverManager::get_driver_count() - 1; AudioDriverManager::initialize(dummy_idx); @@ -311,7 +311,7 @@ struct GodotTestCaseListener : public doctest::IReporter { } #ifndef _3D_DISABLED - if (suite_name.find("[Navigation]") != -1 && navigation_server_2d == nullptr && navigation_server_3d == nullptr) { + if (suite_name.contains("[Navigation]") && navigation_server_2d == nullptr && navigation_server_3d == nullptr) { ERR_PRINT_OFF; navigation_server_3d = NavigationServer3DManager::new_default_server(); navigation_server_2d = NavigationServer2DManager::new_default_server(); -- cgit v1.2.3