nesting.cpp 673 B

12345678910111213141516171819202122232425262728293031
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2025, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonVariantConst::nesting()") {
  7. JsonDocument doc;
  8. JsonVariantConst var = doc.to<JsonVariant>();
  9. SECTION("return 0 if unbound") {
  10. JsonVariantConst unbound;
  11. REQUIRE(unbound.nesting() == 0);
  12. }
  13. SECTION("returns 0 for string") {
  14. doc.set("hello");
  15. REQUIRE(var.nesting() == 0);
  16. }
  17. SECTION("returns 1 for empty object") {
  18. doc.to<JsonObject>();
  19. REQUIRE(var.nesting() == 1);
  20. }
  21. SECTION("returns 1 for empty array") {
  22. doc.to<JsonArray>();
  23. REQUIRE(var.nesting() == 1);
  24. }
  25. }