test: add coverage for closeLeaf's two untested branches

Gap 1: closeLeaf was only tested closing the first sibling; added test
closing the second sibling to cover the else branch of parent->a.get()==leaf.
The test verifies the correct sibling survives with its signal intact.

Gap 2: closeLeaf was only tested at depth 1 (root's direct children);
added test with depth-2 leaf (in right subtree) to exercise findParent's
recursive search in both subtrees. Tests that the correct leaf is promoted
and remaining signals are preserved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino Ferrari
2026-08-27 19:46:29 +02:00
co-authored by Claude Opus 4.6
parent 0e5d103e73
commit ea9689591d
+61
View File
@@ -167,3 +167,64 @@ TEST(PaneTree, HitTestFindsInsetSplitHandlesAndTheCloseButton) {
EXPECT_EQ(PaneTree::hitTestHandle(pane, 392.0, 8.0), Handle::Close);
EXPECT_EQ(PaneTree::hitTestHandle(pane, 200.0, 150.0), Handle::None);
}
// Gap 1: closeLeaf only tested with first child closed; test closing the second child.
TEST(PaneTree, ClosingTheSecondLeafPreservesTheFirstLeafContent) {
PaneTree tree;
tree.splitLeaf(tree.root(), Orient::Columns);
auto leaves = leavesOf(tree, kScreen);
ASSERT_EQ(leaves.size(), 2u);
// Assign distinct signals to each leaf
leaves[0].leaf->signals.push_back(Assignment{"Signal_A", Color{}, 1.5f, VScale{}});
leaves[1].leaf->signals.push_back(Assignment{"Signal_B", Color{}, 1.5f, VScale{}});
// Close the second leaf; the first should survive with its content
tree.closeLeaf(leaves[1].leaf);
EXPECT_EQ(tree.leafCount(), 1u);
leaves = leavesOf(tree, kScreen);
ASSERT_EQ(leaves.size(), 1u);
ASSERT_EQ(leaves[0].leaf->signals.size(), 1u);
EXPECT_EQ(leaves[0].leaf->signals[0].signalName, "Signal_A");
}
// Gap 2: closeLeaf only tested at depth 1; test at depth 2 (deeper recursion in findParent).
TEST(PaneTree, ClosingALeafAtDepth2PreservesOthersAndUpdatesCount) {
PaneTree tree;
// Build tree: split root (a, b), split b to get depth-2 leaf in the RIGHT subtree
tree.splitLeaf(tree.root(), Orient::Columns); // depth 1: root splits into a, b
auto leaves = leavesOf(tree, kScreen);
ASSERT_EQ(leaves.size(), 2u);
tree.splitLeaf(leaves[1].leaf, Orient::Rows); // depth 2: b splits into b.a, b.b
leaves = leavesOf(tree, kScreen);
ASSERT_EQ(leaves.size(), 3u);
// Assign distinct signals to each of the three leaves
leaves[0].leaf->signals.push_back(Assignment{"Depth1_Left", Color{}, 1.5f, VScale{}});
leaves[1].leaf->signals.push_back(Assignment{"Depth2_TopRight", Color{}, 1.5f, VScale{}});
leaves[2].leaf->signals.push_back(Assignment{"Depth2_BottomRight", Color{}, 1.5f, VScale{}});
// Close the first depth-2 leaf (leaves[1], which is in the right subtree)
tree.closeLeaf(leaves[1].leaf);
EXPECT_EQ(tree.leafCount(), 2u);
leaves = leavesOf(tree, kScreen);
ASSERT_EQ(leaves.size(), 2u);
// Verify the surviving depth-2 leaf has its signal intact
bool found_left = false;
bool found_bottom_right = false;
for (const auto& leaf : leaves) {
ASSERT_EQ(leaf.leaf->signals.size(), 1u);
if (leaf.leaf->signals[0].signalName == "Depth1_Left") {
found_left = true;
}
if (leaf.leaf->signals[0].signalName == "Depth2_BottomRight") {
found_bottom_right = true;
}
}
EXPECT_TRUE(found_left);
EXPECT_TRUE(found_bottom_right);
}