Add std::initializer_list constructor for Dictionary.

This commit is contained in:
Pāvels Nadtočajevs 2024-11-27 14:04:41 +02:00
parent 0eadbdb5d0
commit 54945c4d28
4 changed files with 54 additions and 0 deletions

View file

@ -95,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;