mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Added nesting() to JsonArray, JsonDocument, JsonObject, and JsonVariant
This commit is contained in:
@@ -12,6 +12,7 @@ add_executable(JsonArrayTests
|
||||
isNull.cpp
|
||||
iterator.cpp
|
||||
memoryUsage.cpp
|
||||
nesting.cpp
|
||||
remove.cpp
|
||||
size.cpp
|
||||
std_string.cpp
|
||||
|
||||
35
test/JsonArray/nesting.cpp
Normal file
35
test/JsonArray/nesting.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::nesting()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
|
||||
SECTION("return 0 if uninitialized") {
|
||||
JsonArray unitialized;
|
||||
REQUIRE(unitialized.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty array") {
|
||||
REQUIRE(arr.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for flat array") {
|
||||
arr.add("hello");
|
||||
REQUIRE(arr.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 2 with nested array") {
|
||||
arr.createNestedArray();
|
||||
REQUIRE(arr.nesting() == 2);
|
||||
}
|
||||
|
||||
SECTION("returns 2 with nested object") {
|
||||
arr.createNestedObject();
|
||||
REQUIRE(arr.nesting() == 2);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
add_executable(JsonDocumentTests
|
||||
DynamicJsonDocument.cpp
|
||||
nesting.cpp
|
||||
StaticJsonDocument.cpp
|
||||
)
|
||||
|
||||
|
||||
30
test/JsonDocument/nesting.cpp
Normal file
30
test/JsonDocument/nesting.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonDocument::nesting()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("return 0 if uninitialized") {
|
||||
REQUIRE(doc.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 0 for string") {
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
var.set("hello");
|
||||
REQUIRE(doc.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty object") {
|
||||
doc.to<JsonObject>();
|
||||
REQUIRE(doc.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty array") {
|
||||
doc.to<JsonArray>();
|
||||
REQUIRE(doc.nesting() == 1);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ add_executable(JsonObjectTests
|
||||
isNull.cpp
|
||||
iterator.cpp
|
||||
memoryUsage.cpp
|
||||
nesting.cpp
|
||||
remove.cpp
|
||||
size.cpp
|
||||
std_string.cpp
|
||||
|
||||
35
test/JsonObject/nesting.cpp
Normal file
35
test/JsonObject/nesting.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonObject::nesting()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
|
||||
SECTION("return 0 if uninitialized") {
|
||||
JsonObject unitialized;
|
||||
REQUIRE(unitialized.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty object") {
|
||||
REQUIRE(obj.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for flat object") {
|
||||
obj["hello"] = "world";
|
||||
REQUIRE(obj.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 2 with nested array") {
|
||||
obj.createNestedArray("nested");
|
||||
REQUIRE(obj.nesting() == 2);
|
||||
}
|
||||
|
||||
SECTION("returns 2 with nested object") {
|
||||
obj.createNestedObject("nested");
|
||||
REQUIRE(obj.nesting() == 2);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ add_executable(JsonVariantTests
|
||||
is.cpp
|
||||
isnull.cpp
|
||||
memoryUsage.cpp
|
||||
nesting.cpp
|
||||
misc.cpp
|
||||
or.cpp
|
||||
set.cpp
|
||||
|
||||
31
test/JsonVariant/nesting.cpp
Normal file
31
test/JsonVariant/nesting.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonVariant::nesting()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("return 0 if uninitialized") {
|
||||
JsonVariant unitialized;
|
||||
REQUIRE(unitialized.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 0 for string") {
|
||||
var.set("hello");
|
||||
REQUIRE(var.nesting() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty object") {
|
||||
var.to<JsonObject>();
|
||||
REQUIRE(var.nesting() == 1);
|
||||
}
|
||||
|
||||
SECTION("returns 1 for empty array") {
|
||||
var.to<JsonArray>();
|
||||
REQUIRE(var.nesting() == 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user