nesting.cpp 772 B

1234567891011121314151617181920212223242526272829303132333435
  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::nesting()") {
  7. DynamicJsonDocument doc(4096);
  8. JsonArray arr = doc.to<JsonArray>();
  9. SECTION("return 0 if uninitialized") {
  10. JsonArray unitialized;
  11. REQUIRE(unitialized.nesting() == 0);
  12. }
  13. SECTION("returns 1 for empty array") {
  14. REQUIRE(arr.nesting() == 1);
  15. }
  16. SECTION("returns 1 for flat array") {
  17. arr.add("hello");
  18. REQUIRE(arr.nesting() == 1);
  19. }
  20. SECTION("returns 2 with nested array") {
  21. arr.createNestedArray();
  22. REQUIRE(arr.nesting() == 2);
  23. }
  24. SECTION("returns 2 with nested object") {
  25. arr.createNestedObject();
  26. REQUIRE(arr.nesting() == 2);
  27. }
  28. }