summaryrefslogtreecommitdiffstats
path: root/tests/core
diff options
context:
space:
mode:
authorSlashscreen <SlashScreen@users.noreply.github.com>2024-08-11 23:28:32 -0700
committerSlashscreen <SlashScreen@users.noreply.github.com>2024-09-13 00:01:53 -0700
commit89491f4403041ec81e8506a45f00f54033e45202 (patch)
tree38a94b063ee20a0f88a754f016bb11900cc5c2a7 /tests/core
parent88f3b5f9d52f740b24fabfb8bc01b8b7026ba279 (diff)
downloadredot-engine-89491f4403041ec81e8506a45f00f54033e45202.tar.gz
Add callable support for `find` and `rfind` `Array` methods
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/variant/test_array.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h
index 787b8f39d9..15e2cebe09 100644
--- a/tests/core/variant/test_array.h
+++ b/tests/core/variant/test_array.h
@@ -634,6 +634,24 @@ TEST_CASE("[Array] Typed copying") {
a6.clear();
}
+static bool _find_custom_callable(const Variant &p_val) {
+ return (int)p_val % 2 == 0;
+}
+
+TEST_CASE("[Array] Test find_custom") {
+ Array a1 = build_array(1, 3, 4, 5, 8, 9);
+ // Find first even number.
+ int index = a1.find_custom(callable_mp_static(_find_custom_callable));
+ CHECK_EQ(index, 2);
+}
+
+TEST_CASE("[Array] Test rfind_custom") {
+ Array a1 = build_array(1, 3, 4, 5, 8, 9);
+ // Find last even number.
+ int index = a1.rfind_custom(callable_mp_static(_find_custom_callable));
+ CHECK_EQ(index, 4);
+}
+
} // namespace TestArray
#endif // TEST_ARRAY_H