Fix incorrect results when the second-to-last row is deleted
This commit is contained in:
parent
20d9da973b
commit
bab5540cf6
|
@ -269,7 +269,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 || row_ndx + 1 == last_row) {
|
||||
if (row_ndx == last_row) {
|
||||
erase(row_ndx);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ TEST_CASE("[collection_change] move_over()") {
|
|||
c.move_over(4, 5);
|
||||
c.move_over(0, 4);
|
||||
c.move_over(2, 3);
|
||||
c.clean_up_stale_moves();
|
||||
|
||||
REQUIRE_INDICES(c.deletions, 0, 2, 4, 5, 6);
|
||||
REQUIRE_INDICES(c.insertions, 0);
|
||||
|
|
|
@ -385,6 +385,26 @@ TEST_CASE("Results") {
|
|||
advance_and_notify(*r);
|
||||
REQUIRE(notification_calls == 2);
|
||||
}
|
||||
|
||||
SECTION("moving a matching row by deleting all other rows") {
|
||||
r->begin_transaction();
|
||||
table->clear();
|
||||
table->add_empty_row(2);
|
||||
table->set_int(0, 0, 15);
|
||||
table->set_int(0, 1, 5);
|
||||
r->commit_transaction();
|
||||
advance_and_notify(*r);
|
||||
|
||||
write([&] {
|
||||
table->move_last_over(0);
|
||||
table->add_empty_row();
|
||||
table->set_int(0, 1, 3);
|
||||
});
|
||||
|
||||
REQUIRE(notification_calls == 3);
|
||||
REQUIRE(change.deletions.empty());
|
||||
REQUIRE_INDICES(change.insertions, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue