feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -135,6 +135,70 @@ TEST_CASE("[Callable] Argument count") {
|
|||
|
||||
memdelete(my_test);
|
||||
}
|
||||
|
||||
class TestBoundUnboundArgumentCount : public Object {
|
||||
GDCLASS(TestBoundUnboundArgumentCount, Object);
|
||||
|
||||
protected:
|
||||
static void _bind_methods() {
|
||||
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "test_func", &TestBoundUnboundArgumentCount::test_func, MethodInfo("test_func"));
|
||||
}
|
||||
|
||||
public:
|
||||
Variant test_func(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||
Array result;
|
||||
result.resize(p_argcount);
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
result[i] = *p_args[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static String get_output(const Callable &p_callable) {
|
||||
Array effective_args;
|
||||
effective_args.push_back(7);
|
||||
effective_args.push_back(8);
|
||||
effective_args.push_back(9);
|
||||
|
||||
effective_args.resize(3 - p_callable.get_unbound_arguments_count());
|
||||
effective_args.append_array(p_callable.get_bound_arguments());
|
||||
|
||||
return vformat(
|
||||
"%d %d %s %s %s",
|
||||
p_callable.get_unbound_arguments_count(),
|
||||
p_callable.get_bound_arguments_count(),
|
||||
p_callable.get_bound_arguments(),
|
||||
p_callable.call(7, 8, 9),
|
||||
effective_args);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("[Callable] Bound and unbound argument count") {
|
||||
String (*get_output)(const Callable &) = TestBoundUnboundArgumentCount::get_output;
|
||||
|
||||
TestBoundUnboundArgumentCount *test_instance = memnew(TestBoundUnboundArgumentCount);
|
||||
|
||||
Callable test_func = Callable(test_instance, "test_func");
|
||||
|
||||
CHECK(get_output(test_func) == "0 0 [] [7, 8, 9] [7, 8, 9]");
|
||||
CHECK(get_output(test_func.bind(1, 2)) == "0 2 [1, 2] [7, 8, 9, 1, 2] [7, 8, 9, 1, 2]");
|
||||
CHECK(get_output(test_func.bind(1, 2).unbind(1)) == "1 2 [1, 2] [7, 8, 1, 2] [7, 8, 1, 2]");
|
||||
CHECK(get_output(test_func.bind(1, 2).unbind(1).bind(3, 4)) == "0 3 [3, 1, 2] [7, 8, 9, 3, 1, 2] [7, 8, 9, 3, 1, 2]");
|
||||
CHECK(get_output(test_func.bind(1, 2).unbind(1).bind(3, 4).unbind(1)) == "1 3 [3, 1, 2] [7, 8, 3, 1, 2] [7, 8, 3, 1, 2]");
|
||||
|
||||
CHECK(get_output(test_func.bind(1).bind(2).bind(3).unbind(1)) == "1 3 [3, 2, 1] [7, 8, 3, 2, 1] [7, 8, 3, 2, 1]");
|
||||
CHECK(get_output(test_func.bind(1).bind(2).unbind(1).bind(3)) == "0 2 [2, 1] [7, 8, 9, 2, 1] [7, 8, 9, 2, 1]");
|
||||
CHECK(get_output(test_func.bind(1).unbind(1).bind(2).bind(3)) == "0 2 [3, 1] [7, 8, 9, 3, 1] [7, 8, 9, 3, 1]");
|
||||
CHECK(get_output(test_func.unbind(1).bind(1).bind(2).bind(3)) == "0 2 [3, 2] [7, 8, 9, 3, 2] [7, 8, 9, 3, 2]");
|
||||
|
||||
CHECK(get_output(test_func.unbind(1).unbind(1).unbind(1).bind(1, 2, 3)) == "0 0 [] [7, 8, 9] [7, 8, 9]");
|
||||
CHECK(get_output(test_func.unbind(1).unbind(1).bind(1, 2, 3).unbind(1)) == "1 1 [1] [7, 8, 1] [7, 8, 1]");
|
||||
CHECK(get_output(test_func.unbind(1).bind(1, 2, 3).unbind(1).unbind(1)) == "2 2 [1, 2] [7, 1, 2] [7, 1, 2]");
|
||||
CHECK(get_output(test_func.bind(1, 2, 3).unbind(1).unbind(1).unbind(1)) == "3 3 [1, 2, 3] [1, 2, 3] [1, 2, 3]");
|
||||
|
||||
memdelete(test_instance);
|
||||
}
|
||||
|
||||
} // namespace TestCallable
|
||||
|
||||
#endif // TEST_CALLABLE_H
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#ifndef TEST_DICTIONARY_H
|
||||
#define TEST_DICTIONARY_H
|
||||
|
||||
#include "core/variant/dictionary.h"
|
||||
#include "core/variant/typed_dictionary.h"
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
namespace TestDictionary {
|
||||
|
|
@ -66,8 +66,7 @@ TEST_CASE("[Dictionary] Assignment using bracket notation ([])") {
|
|||
|
||||
map[StringName("HelloName")] = 6;
|
||||
CHECK(int(map[StringName("HelloName")]) == 6);
|
||||
// Check that StringName key is converted to String.
|
||||
CHECK(int(map.find_key(6).get_type()) == Variant::STRING);
|
||||
CHECK(int(map.find_key(6).get_type()) == Variant::STRING_NAME);
|
||||
map[StringName("HelloName")] = 7;
|
||||
CHECK(int(map[StringName("HelloName")]) == 7);
|
||||
|
||||
|
|
@ -96,6 +95,27 @@ TEST_CASE("[Dictionary] Assignment using bracket notation ([])") {
|
|||
CHECK(map.size() == length);
|
||||
}
|
||||
|
||||
TEST_CASE("[Dictionary] List init") {
|
||||
Dictionary dict{
|
||||
{ 0, "int" },
|
||||
{ "packed_string_array", PackedStringArray({ "array", "of", "values" }) },
|
||||
{ "key", Dictionary({ { "nested", 200 } }) },
|
||||
{ Vector2(), "v2" },
|
||||
};
|
||||
CHECK(dict.size() == 4);
|
||||
CHECK(dict[0] == "int");
|
||||
CHECK(PackedStringArray(dict["packed_string_array"])[2] == "values");
|
||||
CHECK(Dictionary(dict["key"])["nested"] == Variant(200));
|
||||
CHECK(dict[Vector2()] == "v2");
|
||||
|
||||
TypedDictionary<double, double> tdict{
|
||||
{ 0.0, 1.0 },
|
||||
{ 5.0, 2.0 },
|
||||
};
|
||||
CHECK_EQ(tdict[0.0], Variant(1.0));
|
||||
CHECK_EQ(tdict[5.0], Variant(2.0));
|
||||
}
|
||||
|
||||
TEST_CASE("[Dictionary] get_key_lists()") {
|
||||
Dictionary map;
|
||||
List<Variant> keys;
|
||||
|
|
@ -537,6 +557,43 @@ TEST_CASE("[Dictionary] Order and find") {
|
|||
CHECK_EQ(d.find_key("does not exist"), Variant());
|
||||
}
|
||||
|
||||
TEST_CASE("[Dictionary] Typed copying") {
|
||||
TypedDictionary<int, int> d1;
|
||||
d1[0] = 1;
|
||||
|
||||
TypedDictionary<double, double> d2;
|
||||
d2[0] = 1.0;
|
||||
|
||||
Dictionary d3 = d1;
|
||||
TypedDictionary<int, int> d4 = d3;
|
||||
|
||||
Dictionary d5 = d2;
|
||||
TypedDictionary<int, int> d6 = d5;
|
||||
|
||||
d3[0] = 2;
|
||||
d4[0] = 3;
|
||||
|
||||
// Same typed TypedDictionary should be shared.
|
||||
CHECK_EQ(d1[0], Variant(3));
|
||||
CHECK_EQ(d3[0], Variant(3));
|
||||
CHECK_EQ(d4[0], Variant(3));
|
||||
|
||||
d5[0] = 2.0;
|
||||
d6[0] = 3.0;
|
||||
|
||||
// Different typed TypedDictionary should not be shared.
|
||||
CHECK_EQ(d2[0], Variant(2.0));
|
||||
CHECK_EQ(d5[0], Variant(2.0));
|
||||
CHECK_EQ(d6[0], Variant(3.0));
|
||||
|
||||
d1.clear();
|
||||
d2.clear();
|
||||
d3.clear();
|
||||
d4.clear();
|
||||
d5.clear();
|
||||
d6.clear();
|
||||
}
|
||||
|
||||
} // namespace TestDictionary
|
||||
|
||||
#endif // TEST_DICTIONARY_H
|
||||
|
|
|
|||
|
|
@ -1806,6 +1806,14 @@ TEST_CASE("[Variant] Writer and parser dictionary") {
|
|||
CHECK_MESSAGE(d_parsed == Variant(d), "Should parse back.");
|
||||
}
|
||||
|
||||
TEST_CASE("[Variant] Writer key sorting") {
|
||||
Dictionary d = build_dictionary(StringName("C"), 3, "A", 1, StringName("B"), 2, "D", 4);
|
||||
String d_str;
|
||||
VariantWriter::write_to_string(d, d_str);
|
||||
|
||||
CHECK_EQ(d_str, "{\n\"A\": 1,\n&\"B\": 2,\n&\"C\": 3,\n\"D\": 4\n}");
|
||||
}
|
||||
|
||||
TEST_CASE("[Variant] Writer recursive dictionary") {
|
||||
// There is no way to accurately represent a recursive dictionary,
|
||||
// the only thing we can do is make sure the writer doesn't blow up
|
||||
|
|
|
|||
|
|
@ -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)]"));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue