Add JsonVariant::link() (resolves #1343)

This commit is contained in:
Benoit Blanchon
2022-04-27 15:06:58 +02:00
parent 5577d18377
commit 3d6c328a4f
35 changed files with 649 additions and 51 deletions

View File

@ -245,3 +245,11 @@ TEST_CASE("ElementProxy cast to JsonVariant") {
CHECK(doc.as<std::string>() == "[\"toto\"]");
}
TEST_CASE("ElementProxy::link()") {
StaticJsonDocument<1024> doc1, doc2;
doc1[0].link(doc2);
doc2["hello"] = "world";
CHECK(doc1.as<std::string>() == "[{\"hello\":\"world\"}]");
}

View File

@ -318,3 +318,10 @@ TEST_CASE("MemberProxy::createNestedObject(key)") {
CHECK(doc["status"]["weather"]["temp"] == 42);
}
TEST_CASE("MemberProxy::link()") {
StaticJsonDocument<1024> doc1, doc2;
doc1["obj"].link(doc2);
doc2["hello"] = "world";
CHECK(doc1.as<std::string>() == "{\"obj\":{\"hello\":\"world\"}}");
}

View File

@ -25,4 +25,21 @@ TEST_CASE("JsonDocument::size()") {
REQUIRE(doc.size() == 2);
}
SECTION("linked array") {
StaticJsonDocument<128> doc2;
doc2.add(1);
doc2.add(2);
doc.as<JsonVariant>().link(doc2);
REQUIRE(doc.size() == 2);
}
SECTION("linked object") {
StaticJsonDocument<128> doc2;
doc2["hello"] = "world";
doc.as<JsonVariant>().link(doc2);
REQUIRE(doc.size() == 1);
}
}