Closed
Description
Consider this new test case that captures the issue:
TEST(JSON_object, erase_must_not_affect_ordering) {
sourcemeta::core::JSON document{{"x", sourcemeta::core::JSON{1}},
{"y", sourcemeta::core::JSON{2}},
{"z", sourcemeta::core::JSON{2}}};
auto before_iterator = document.as_object().begin();
EXPECT_EQ(before_iterator->first, "x");
std::advance(before_iterator, 1);
EXPECT_EQ(before_iterator->first, "y");
std::advance(before_iterator, 1);
EXPECT_EQ(before_iterator->first, "z");
document.erase("x");
auto after_iterator = document.as_object().begin();
EXPECT_EQ(after_iterator->first, "y");
std::advance(after_iterator, 1);
EXPECT_EQ(after_iterator->first, "z");
}
The problems seems to be that FlatMap
will swap elements on removal to avoid moving multiple keys. But changing ordering is problematic for other reasons (like linting)