From bab5540cf64ef0c440a14654f1ca45cc34556b55 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 22 Mar 2016 11:37:05 -0700 Subject: [PATCH] Fix incorrect results when the second-to-last row is deleted --- src/collection_notifications.cpp | 2 +- tests/collection_change_indices.cpp | 1 + tests/results.cpp | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 0457211d..99c40714 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -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; } diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index 4c8dd2e6..d02ed52b 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -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); diff --git a/tests/results.cpp b/tests/results.cpp index e0216c59..fb039d44 100644 --- a/tests/results.cpp +++ b/tests/results.cpp @@ -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); + } } }