size.cpp 756 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2023
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonArray::size()") {
  7. DynamicJsonBuffer _jsonBuffer;
  8. JsonArray& _array = _jsonBuffer.createArray();
  9. SECTION("increases after add()") {
  10. _array.add("hello");
  11. REQUIRE(1U == _array.size());
  12. _array.add("world");
  13. REQUIRE(2U == _array.size());
  14. }
  15. SECTION("remains the same after set()") {
  16. _array.add("hello");
  17. REQUIRE(1U == _array.size());
  18. _array.set(0, "hello");
  19. REQUIRE(1U == _array.size());
  20. }
  21. SECTION("remains the same after assigment") {
  22. _array.add("hello");
  23. REQUIRE(1U == _array.size());
  24. _array[0] = "hello";
  25. REQUIRE(1U == _array.size());
  26. }
  27. }