subscript.cpp 549 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("MemberProxy::operator[]") {
  8. DynamicJsonDocument doc(4096);
  9. MemberProxy<JsonDocument&, const char*> mp = doc["hello"];
  10. SECTION("set member") {
  11. mp["world"] = 42;
  12. REQUIRE(doc.as<std::string>() == "{\"hello\":{\"world\":42}}");
  13. }
  14. SECTION("set element") {
  15. mp[2] = 42;
  16. REQUIRE(doc.as<std::string>() == "{\"hello\":[null,null,42]}");
  17. }
  18. }