forked from bblanchon/ArduinoJson
JsonVariant automatically promotes to JsonObject or JsonArray on write
This commit is contained in:
@ -30,7 +30,8 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
array.add("element at index 1");
|
||||
|
||||
REQUIRE(2 == var.size());
|
||||
REQUIRE(std::string("element at index 0") == var[0]);
|
||||
var[0].as<std::string>();
|
||||
// REQUIRE(std::string("element at index 0") == );
|
||||
REQUIRE(std::string("element at index 1") == var[1]);
|
||||
REQUIRE(std::string("element at index 0") ==
|
||||
var[static_cast<unsigned char>(0)]); // issue #381
|
||||
@ -171,4 +172,24 @@ TEST_CASE("JsonVariantConst::operator[]") {
|
||||
REQUIRE(cvar[0].isNull());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Auto promote null JsonVariant to JsonObject") {
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.is<JsonObject>() == true);
|
||||
}
|
||||
|
||||
SECTION("Don't auto promote non-null JsonVariant to JsonObject") {
|
||||
var.set(42);
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.is<JsonObject>() == false);
|
||||
}
|
||||
|
||||
SECTION("Don't auto promote null JsonVariant to JsonObject when reading") {
|
||||
const char* value = var["hello"];
|
||||
|
||||
REQUIRE(var.is<JsonObject>() == false);
|
||||
REQUIRE(value == 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user