summaryrefslogtreecommitdiffstats
path: root/tests/scene/test_tree.h
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-08-28 12:03:57 +0200
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-08-28 12:40:26 +0200
commitcd4221c1e20353124f086111d8f575cc3da62d76 (patch)
tree180637eee6880428093846f4fe82a3765d6612fd /tests/scene/test_tree.h
parent108c603f91b94100a1adc989316a372f0a6f8989 (diff)
downloadredot-engine-cd4221c1e20353124f086111d8f575cc3da62d76.tar.gz
[Tree] Fix error when removing child from `Tree`
New `last_child` member was not properly updated
Diffstat (limited to 'tests/scene/test_tree.h')
-rw-r--r--tests/scene/test_tree.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/scene/test_tree.h b/tests/scene/test_tree.h
index 41ef39d621..e19f8311e2 100644
--- a/tests/scene/test_tree.h
+++ b/tests/scene/test_tree.h
@@ -108,6 +108,30 @@ TEST_CASE("[SceneTree][Tree]") {
memdelete(tree);
}
+ // https://github.com/godotengine/godot/issues/96205
+ SUBCASE("[Tree] Get last item after removal.") {
+ Tree *tree = memnew(Tree);
+ TreeItem *root = tree->create_item();
+
+ TreeItem *child1 = tree->create_item(root);
+ TreeItem *child2 = tree->create_item(root);
+
+ CHECK_EQ(root->get_child_count(), 2);
+ CHECK_EQ(tree->get_last_item(), child2);
+
+ root->remove_child(child2);
+
+ CHECK_EQ(root->get_child_count(), 1);
+ CHECK_EQ(tree->get_last_item(), child1);
+
+ root->add_child(child2);
+
+ CHECK_EQ(root->get_child_count(), 2);
+ CHECK_EQ(tree->get_last_item(), child2);
+
+ memdelete(tree);
+ }
+
SUBCASE("[Tree] Previous and Next items.") {
Tree *tree = memnew(Tree);
TreeItem *root = tree->create_item();