size.cpp 869 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include <string>
  7. TEST_CASE("JsonObject::size()") {
  8. DynamicJsonDocument doc(4096);
  9. JsonObject obj = doc.to<JsonObject>();
  10. SECTION("initial size is zero") {
  11. REQUIRE(0 == obj.size());
  12. }
  13. SECTION("increases when values are added") {
  14. obj["hello"] = 42;
  15. REQUIRE(1 == obj.size());
  16. }
  17. SECTION("decreases when values are removed") {
  18. obj["hello"] = 42;
  19. obj.remove("hello");
  20. REQUIRE(0 == obj.size());
  21. }
  22. SECTION("doesn't increase when the same key is added twice") {
  23. obj["hello"] = 1;
  24. obj["hello"] = 2;
  25. REQUIRE(1 == obj.size());
  26. }
  27. SECTION("doesn't decrease when another key is removed") {
  28. obj["hello"] = 1;
  29. obj.remove("world");
  30. REQUIRE(1 == obj.size());
  31. }
  32. }