Test add() on linked array

This commit is contained in:
Benoit Blanchon
2022-03-10 18:52:08 +01:00
parent a215d70af6
commit b04471c7a8
2 changed files with 12 additions and 3 deletions

View File

@@ -43,4 +43,14 @@ TEST_CASE("JsonVariant::add()") {
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]");
}
}

View File

@@ -138,13 +138,12 @@ TEST_CASE("JsonVariant::operator[]") {
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;
doc2["hello"] = "world";
var.link(doc2);
// The link is read-only; the following line should have no side effect
var["tutu"] = "toto";
var["tutu"] = "toto"; // no-op
CHECK(doc.as<std::string>() == "{\"hello\":\"world\"}");
CHECK(doc2.as<std::string>() == "{\"hello\":\"world\"}");