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

@ -67,6 +67,15 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(var.is<int>());
REQUIRE(var.as<int>() == 123);
}
SECTION("use JsonVariant as index") {
array.add("A");
array.add("B");
array.add(1);
REQUIRE(var[var[2]] == "B");
REQUIRE(var[var[3]].isNull());
}
}
SECTION("The JsonVariant is a JsonObject") {
@ -103,6 +112,15 @@ TEST_CASE("JsonVariant::operator[]") {
JsonArray arr = var["hello"].to<JsonArray>();
REQUIRE(arr.isNull() == false);
}
SECTION("use JsonVariant as key") {
object["a"] = "a";
object["b"] = "b";
object["c"] = "b";
REQUIRE(var[var["c"]] == "b");
REQUIRE(var[var["d"]].isNull());
}
}
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \