size.cpp 664 B

12345678910111213141516171819202122232425262728293031
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonArray::size()") {
  7. DynamicJsonDocument doc(4096);
  8. JsonArray array = doc.to<JsonArray>();
  9. SECTION("returns 0 is empty") {
  10. REQUIRE(0U == array.size());
  11. }
  12. SECTION("increases after add()") {
  13. array.add("hello");
  14. REQUIRE(1U == array.size());
  15. array.add("world");
  16. REQUIRE(2U == array.size());
  17. }
  18. SECTION("remains the same after replacing an element") {
  19. array.add("hello");
  20. REQUIRE(1U == array.size());
  21. array[0] = "hello";
  22. REQUIRE(1U == array.size());
  23. }
  24. }