Allow using a JsonVariant as a key or index

Closes #2080
This commit is contained in:
Benoit Blanchon
2024-05-14 21:06:02 +02:00
parent 071f718473
commit 68a13117dc
26 changed files with 393 additions and 34 deletions

View File

@ -88,6 +88,15 @@ TEST_CASE("JsonArray::remove()") {
JsonArray unboundArray;
unboundArray.remove(unboundArray.begin());
}
SECTION("use JsonVariant as index") {
array.remove(array[3]); // no effect with null variant
array.remove(array[0]); // remove element at index 1
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 3);
}
}
TEST_CASE("Removed elements are recycled") {

View File

@ -164,4 +164,13 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(std::string("world") == array[0]);
}
#endif
SECTION("Use a JsonVariant as index") {
array[0] = 1;
array[1] = 2;
array[2] = 3;
REQUIRE(array[array[1]] == 3);
REQUIRE(array[array[3]] == nullptr);
}
}