Fix handling of move_last_over() on the second-to-last row

This commit is contained in:
Thomas Goyne 2016-03-21 10:39:23 -07:00
parent 47cee90d32
commit 1289c4806c
2 changed files with 12 additions and 1 deletions

View File

@ -263,7 +263,7 @@ void CollectionChangeBuilder::move(size_t from, size_t to)
void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
{
REALM_ASSERT(row_ndx <= last_row);
if (row_ndx == last_row) {
if (row_ndx == last_row || row_ndx + 1 == last_row) {
erase(row_ndx);
return;
}

View File

@ -126,6 +126,17 @@ TEST_CASE("[collection_change] move_over()") {
REQUIRE(c.moves.empty());
}
SECTION("is just erase when row + 1 == last_row") {
c.move_over(0, 6);
c.move_over(4, 5);
c.move_over(0, 4);
c.move_over(2, 3);
REQUIRE_INDICES(c.deletions, 0, 2, 4, 5, 6);
REQUIRE_INDICES(c.insertions, 0);
REQUIRE_MOVES(c, {5, 0});
}
SECTION("marks the old last row as moved") {
c.move_over(5, 8);
REQUIRE_MOVES(c, {8, 5});