size.cpp 581 B

123456789101112131415161718192021222324252627
  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::size()") {
  8. DynamicJsonDocument doc;
  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.set("hello", 42);
  15. REQUIRE(1 == obj.size());
  16. }
  17. SECTION("doesn't increase when the smae key is added twice") {
  18. obj["hello"] = 1;
  19. obj["hello"] = 2;
  20. REQUIRE(1 == obj.size());
  21. }
  22. }