Fix marking deletions when chaining move_last_over()

This commit is contained in:
Thomas Goyne 2016-03-21 11:15:29 -07:00
parent 51edc6909c
commit 0a3158ce74
2 changed files with 21 additions and 2 deletions

View File

@ -292,8 +292,17 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
move.to = row_ndx; move.to = row_ndx;
updated_existing_move = true; updated_existing_move = true;
insertions.erase_at(last_row); if (!insertions.empty()) {
insertions.insert_at(row_ndx); REALM_ASSERT(std::prev(insertions.end())->second - 1 <= last_row);
insertions.remove(last_row);
}
// Don't mark the moved-over row as deleted if it was a new insertion
if (!insertions.contains(row_ndx)) {
deletions.add_shifted(insertions.unshift(row_ndx));
insertions.add(row_ndx);
}
// Because this is a move, the unshifted source row has already been marked as deleted // Because this is a move, the unshifted source row has already been marked as deleted
} }
@ -312,6 +321,7 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
deletions.add_shifted(insertions.unshift(row_ndx)); deletions.add_shifted(insertions.unshift(row_ndx));
insertions.add(row_ndx); insertions.add(row_ndx);
} }
verify();
} }
void CollectionChangeBuilder::verify() void CollectionChangeBuilder::verify()

View File

@ -185,6 +185,15 @@ TEST_CASE("[collection_change] move_over()") {
REQUIRE_INDICES(c.insertions, 5, 6); REQUIRE_INDICES(c.insertions, 5, 6);
REQUIRE_MOVES(c, {10, 5}, {9, 6}); REQUIRE_MOVES(c, {10, 5}, {9, 6});
} }
SECTION("marks the moved-over row as deleted when chaining moves") {
c.move_over(5, 10);
c.move_over(0, 5);
REQUIRE_INDICES(c.deletions, 0, 5, 10);
REQUIRE_INDICES(c.insertions, 0);
REQUIRE_MOVES(c, {10, 0});
}
} }
TEST_CASE("[collection_change] clear()") { TEST_CASE("[collection_change] clear()") {