nesting.cpp 788 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObject::nesting()") {
  7. DynamicJsonDocument doc(4096);
  8. JsonObject obj = doc.to<JsonObject>();
  9. SECTION("return 0 if uninitialized") {
  10. JsonObject unitialized;
  11. REQUIRE(unitialized.nesting() == 0);
  12. }
  13. SECTION("returns 1 for empty object") {
  14. REQUIRE(obj.nesting() == 1);
  15. }
  16. SECTION("returns 1 for flat object") {
  17. obj["hello"] = "world";
  18. REQUIRE(obj.nesting() == 1);
  19. }
  20. SECTION("returns 2 with nested array") {
  21. obj.createNestedArray("nested");
  22. REQUIRE(obj.nesting() == 2);
  23. }
  24. SECTION("returns 2 with nested object") {
  25. obj.createNestedObject("nested");
  26. REQUIRE(obj.nesting() == 2);
  27. }
  28. }