forked from bblanchon/ArduinoJson
Added JsonArrayConst
, JsonObjectConst
, and JsonVariantConst
This commit is contained in:
@ -120,3 +120,55 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariantConst::operator[]") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
JsonVariantConst cvar = var;
|
||||
|
||||
SECTION("The JsonVariant is undefined") {
|
||||
REQUIRE(0 == cvar.size());
|
||||
REQUIRE(cvar["0"].isNull());
|
||||
REQUIRE(cvar[0].isNull());
|
||||
}
|
||||
|
||||
SECTION("The JsonVariant is a string") {
|
||||
var.set("hello world");
|
||||
REQUIRE(0 == cvar.size());
|
||||
REQUIRE(cvar["0"].isNull());
|
||||
REQUIRE(cvar[0].isNull());
|
||||
}
|
||||
|
||||
SECTION("The JsonVariant is a JsonArray") {
|
||||
JsonArray array = var.to<JsonArray>();
|
||||
|
||||
SECTION("get value") {
|
||||
array.add("element at index 0");
|
||||
array.add("element at index 1");
|
||||
|
||||
REQUIRE(2 == cvar.size());
|
||||
REQUIRE(std::string("element at index 0") == cvar[0]);
|
||||
REQUIRE(std::string("element at index 1") == cvar[1]);
|
||||
REQUIRE(std::string("element at index 0") ==
|
||||
var[static_cast<unsigned char>(0)]); // issue #381
|
||||
REQUIRE(cvar[666].isNull());
|
||||
REQUIRE(cvar[3].isNull());
|
||||
REQUIRE(cvar["0"].isNull());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("The JsonVariant is a JsonObject") {
|
||||
JsonObject object = var.to<JsonObject>();
|
||||
|
||||
SECTION("get value") {
|
||||
object["a"] = "element at key \"a\"";
|
||||
object["b"] = "element at key \"b\"";
|
||||
|
||||
REQUIRE(2 == cvar.size());
|
||||
REQUIRE(std::string("element at key \"a\"") == cvar["a"]);
|
||||
REQUIRE(std::string("element at key \"b\"") == cvar["b"]);
|
||||
REQUIRE(cvar["c"].isNull());
|
||||
REQUIRE(cvar[0].isNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user