remove.cpp 810 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include <string>
  7. TEST_CASE("JsonObject::remove()") {
  8. DynamicJsonObject obj;
  9. SECTION("SizeDecreased_WhenValuesAreRemoved") {
  10. obj["hello"] = 1;
  11. obj.remove("hello");
  12. REQUIRE(0 == obj.size());
  13. }
  14. SECTION("SizeUntouched_WhenRemoveIsCalledWithAWrongKey") {
  15. obj["hello"] = 1;
  16. obj.remove("world");
  17. REQUIRE(1 == obj.size());
  18. }
  19. SECTION("RemoveByIterator") {
  20. deserializeJson(obj, "{\"a\":0,\"b\":1,\"c\":2}");
  21. for (JsonObject::iterator it = obj.begin(); it != obj.end(); ++it) {
  22. if (it->value == 1) obj.remove(it);
  23. }
  24. std::string result;
  25. serializeJson(obj, result);
  26. REQUIRE("{\"a\":0,\"c\":2}" == result);
  27. }
  28. }