nesting.cpp 685 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("JsonVariant::nesting()") {
  7. DynamicJsonDocument doc(4096);
  8. JsonVariant var = doc.to<JsonVariant>();
  9. SECTION("return 0 if uninitialized") {
  10. JsonVariant unitialized;
  11. REQUIRE(unitialized.nesting() == 0);
  12. }
  13. SECTION("returns 0 for string") {
  14. var.set("hello");
  15. REQUIRE(var.nesting() == 0);
  16. }
  17. SECTION("returns 1 for empty object") {
  18. var.to<JsonObject>();
  19. REQUIRE(var.nesting() == 1);
  20. }
  21. SECTION("returns 1 for empty array") {
  22. var.to<JsonArray>();
  23. REQUIRE(var.nesting() == 1);
  24. }
  25. }