Skip to content

Commit

Permalink
Update object relocation to give more info.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadden committed Jun 12, 2020
1 parent 82c8938 commit 6260439
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/alia/flow/object_trees.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ check_for_movement(tree_traversal<Object>& traversal, tree_node<Object>& node)
node.remove_from_list();
node.object.relocate(
traversal.active_parent->object,
traversal.last_sibling ? &traversal.last_sibling->object : nullptr);
traversal.last_sibling ? &traversal.last_sibling->object : nullptr,
expected_node ? &expected_node->object : nullptr);
node.insert_into_list(traversal.next_ptr, expected_node);
}
}
Expand Down
17 changes: 14 additions & 3 deletions unit_tests/flow/object_trees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct test_object
}

void
relocate(test_object& new_parent, test_object* after)
relocate(test_object& new_parent, test_object* after, test_object* before)
{
the_log << "relocating " << name << " into " << new_parent.name;
if (after)
Expand All @@ -38,14 +38,25 @@ struct test_object
this->parent = &new_parent;

auto& siblings = new_parent.children;
std::vector<test_object*>::iterator insertion_point;
if (after)
{
siblings.insert(
insertion_point = siblings.insert(
std::find(siblings.begin(), siblings.end(), after) + 1, this);
}
else
{
siblings.insert(siblings.begin(), this);
insertion_point = siblings.insert(siblings.begin(), this);
}

++insertion_point;
if (before)
{
REQUIRE(*insertion_point == before);
}
else
{
REQUIRE(insertion_point == siblings.end());
}
}

Expand Down

0 comments on commit 6260439

Please sign in to comment.