remove.cpp 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("MemberProxy::remove()") {
  8. DynamicJsonDocument doc(4096);
  9. MemberProxy<JsonDocument&, const char*> mp = doc["hello"];
  10. SECTION("remove(int)") {
  11. mp.add(1);
  12. mp.add(2);
  13. mp.add(3);
  14. mp.remove(1);
  15. REQUIRE(mp.as<std::string>() == "[1,3]");
  16. }
  17. SECTION("remove(const char *)") {
  18. mp["a"] = 1;
  19. mp["b"] = 2;
  20. mp.remove("a");
  21. REQUIRE(mp.as<std::string>() == "{\"b\":2}");
  22. }
  23. SECTION("remove(std::string)") {
  24. mp["a"] = 1;
  25. mp["b"] = 2;
  26. mp.remove(std::string("b"));
  27. REQUIRE(mp.as<std::string>() == "{\"a\":1}");
  28. }
  29. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  30. SECTION("remove(vla)") {
  31. mp["a"] = 1;
  32. mp["b"] = 2;
  33. int i = 4;
  34. char vla[i];
  35. strcpy(vla, "b");
  36. mp.remove(vla);
  37. REQUIRE(mp.as<std::string>() == "{\"a\":1}");
  38. }
  39. #endif
  40. }