mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Test add() on linked array
This commit is contained in:
@@ -43,4 +43,14 @@ TEST_CASE("JsonVariant::add()") {
|
|||||||
|
|
||||||
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("add to linked array") {
|
||||||
|
StaticJsonDocument<1024> doc2;
|
||||||
|
doc2.add(42);
|
||||||
|
var.link(doc2);
|
||||||
|
|
||||||
|
var.add(666); // no-op
|
||||||
|
|
||||||
|
CHECK(var.as<std::string>() == "[42]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,13 +138,12 @@ TEST_CASE("JsonVariant::operator[]") {
|
|||||||
CHECK(var["hello"].as<std::string>() == "world");
|
CHECK(var["hello"].as<std::string>() == "world");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("try to set value to linked object") {
|
SECTION("set value to linked object") {
|
||||||
StaticJsonDocument<1024> doc1, doc2;
|
StaticJsonDocument<1024> doc1, doc2;
|
||||||
doc2["hello"] = "world";
|
doc2["hello"] = "world";
|
||||||
var.link(doc2);
|
var.link(doc2);
|
||||||
|
|
||||||
// The link is read-only; the following line should have no side effect
|
var["tutu"] = "toto"; // no-op
|
||||||
var["tutu"] = "toto";
|
|
||||||
|
|
||||||
CHECK(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
CHECK(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
CHECK(doc2.as<std::string>() == "{\"hello\":\"world\"}");
|
CHECK(doc2.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
|
|||||||
Reference in New Issue
Block a user