From 4d7f03836c9331e82e314bc2c8f2a9aff86dcfe8 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 30 Jul 2020 09:20:31 +0200 Subject: [PATCH] Added a test that removes an element during iteration (#1332) --- extras/tests/JsonArray/remove.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extras/tests/JsonArray/remove.cpp b/extras/tests/JsonArray/remove.cpp index 20203148..4113d71e 100644 --- a/extras/tests/JsonArray/remove.cpp +++ b/extras/tests/JsonArray/remove.cpp @@ -65,4 +65,15 @@ TEST_CASE("JsonArray::remove()") { REQUIRE(_array[0] == 1); REQUIRE(_array[1] == 2); } + + SECTION("In a loop") { + for (JsonArray::iterator it = _array.begin(); it != _array.end(); ++it) { + if (*it == 2) + _array.remove(it); + } + + REQUIRE(2 == _array.size()); + REQUIRE(_array[0] == 1); + REQUIRE(_array[1] == 3); + } }