From 412ca3e5faffde72ee69e7da1dd15a3cce73074c Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 10 Mar 2022 18:48:17 +0100 Subject: [PATCH] Move get set tests --- extras/tests/JsonVariant/link.cpp | 18 ------------------ extras/tests/JsonVariant/subscript.cpp | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extras/tests/JsonVariant/link.cpp b/extras/tests/JsonVariant/link.cpp index 5e4662d8..6c6ebdb3 100644 --- a/extras/tests/JsonVariant/link.cpp +++ b/extras/tests/JsonVariant/link.cpp @@ -51,21 +51,3 @@ TEST_CASE("JsonVariant::link()") { CHECK(variant.as() == "{\"hello\":\"WORLD!\"}"); } } - -TEST_CASE("Linked document") { - StaticJsonDocument<1024> doc1, doc2; - JsonVariant variant = doc1.to(); - doc2["hello"] = "world"; - variant.link(doc2); - - SECTION("get member") { - CHECK(variant["hello"].as() == "world"); - } - - SECTION("set member") { - // The link is read-only; the following line should have no side effect - variant["tutu"] = "toto"; - - CHECK(doc1.as() == "{\"hello\":\"world\"}"); - } -} diff --git a/extras/tests/JsonVariant/subscript.cpp b/extras/tests/JsonVariant/subscript.cpp index f466cd27..9874819c 100644 --- a/extras/tests/JsonVariant/subscript.cpp +++ b/extras/tests/JsonVariant/subscript.cpp @@ -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() == "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() == "{\"hello\":\"world\"}"); + CHECK(doc2.as() == "{\"hello\":\"world\"}"); + } } TEST_CASE("JsonVariantConst::operator[]") {