Move get set tests

This commit is contained in:
Benoit Blanchon
2022-03-10 18:48:17 +01:00
parent cf1d19fec5
commit 412ca3e5fa
2 changed files with 20 additions and 18 deletions

View File

@@ -51,21 +51,3 @@ TEST_CASE("JsonVariant::link()") {
CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
}
}
TEST_CASE("Linked document") {
StaticJsonDocument<1024> doc1, doc2;
JsonVariant variant = doc1.to<JsonVariant>();
doc2["hello"] = "world";
variant.link(doc2);
SECTION("get member") {
CHECK(variant["hello"].as<std::string>() == "world");
}
SECTION("set member") {
// The link is read-only; the following line should have no side effect
variant["tutu"] = "toto";
CHECK(doc1.as<std::string>() == "{\"hello\":\"world\"}");
}
}

View File

@@ -129,6 +129,26 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(std::string("world") == variant[vla]);
}
#endif
SECTION("get value from linked object") {
StaticJsonDocument<1024> doc1, doc2;
doc2["hello"] = "world";
var.link(doc2);
CHECK(var["hello"].as<std::string>() == "world");
}
SECTION("try to 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";
CHECK(doc.as<std::string>() == "{\"hello\":\"world\"}");
CHECK(doc2.as<std::string>() == "{\"hello\":\"world\"}");
}
}
TEST_CASE("JsonVariantConst::operator[]") {