subscript.cpp 522 B

12345678910111213141516171819202122232425
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2020
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("ElementProxy::operator[]") {
  8. DynamicJsonDocument doc(4096);
  9. ElementProxy<JsonDocument&> ep = doc[1];
  10. SECTION("set member") {
  11. ep["world"] = 42;
  12. REQUIRE(doc.as<std::string>() == "[null,{\"world\":42}]");
  13. }
  14. SECTION("set element") {
  15. ep[2] = 42;
  16. REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
  17. }
  18. }