mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Move get set tests
This commit is contained in:
@@ -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\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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[]") {
|
||||
|
||||
Reference in New Issue
Block a user