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

@ -27,13 +27,24 @@ TEST_CASE("JsonVariantConst::operator[]") {
array.add("A");
array.add("B");
REQUIRE(std::string("A") == var[0]);
REQUIRE(std::string("B") == var[1]);
REQUIRE(std::string("A") ==
var[static_cast<unsigned char>(0)]); // issue #381
REQUIRE(var[666].isNull());
REQUIRE(var[3].isNull());
REQUIRE(var["0"].isNull());
SECTION("int") {
REQUIRE(std::string("A") == var[0]);
REQUIRE(std::string("B") == var[1]);
REQUIRE(std::string("A") ==
var[static_cast<unsigned char>(0)]); // issue #381
REQUIRE(var[666].isNull());
REQUIRE(var[3].isNull());
}
SECTION("const char*") {
REQUIRE(var["0"].isNull());
}
SECTION("JsonVariant") {
array.add(1);
REQUIRE(var[var[2]] == std::string("B"));
REQUIRE(var[var[3]].isNull());
}
}
SECTION("object") {
@ -64,5 +75,11 @@ TEST_CASE("JsonVariantConst::operator[]") {
REQUIRE(std::string("A") == var[vla]);
}
#endif
SECTION("supports JsonVariant") {
object["c"] = "b";
REQUIRE(var[var["c"]] == "B");
REQUIRE(var[var["d"]].isNull());
}
}
}