remove.cpp 744 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2023, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <stdint.h>
  6. #include <catch.hpp>
  7. TEST_CASE("JsonVariant::remove()") {
  8. DynamicJsonDocument doc(4096);
  9. JsonVariant var = doc.to<JsonVariant>();
  10. SECTION("remove(int)") {
  11. var.add(1);
  12. var.add(2);
  13. var.add(3);
  14. var.remove(1);
  15. REQUIRE(var.as<std::string>() == "[1,3]");
  16. }
  17. SECTION("remove(const char *)") {
  18. var["a"] = 1;
  19. var["b"] = 2;
  20. var.remove("a");
  21. REQUIRE(var.as<std::string>() == "{\"b\":2}");
  22. }
  23. SECTION("remove(std::string)") {
  24. var["a"] = 1;
  25. var["b"] = 2;
  26. var.remove(std::string("b"));
  27. REQUIRE(var.as<std::string>() == "{\"a\":1}");
  28. }
  29. }