mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 18:27:37 +02:00
Replace add()
with add<T>()
(add(T)
is still supported)
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
|
||||
TEST_CASE("JsonArray::add()") {
|
||||
TEST_CASE("JsonArray::add(T)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -154,3 +154,28 @@ TEST_CASE("JsonArray::add()") {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::add<T>()") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
SECTION("add<JsonArray>()") {
|
||||
JsonArray nestedArray = array.add<JsonArray>();
|
||||
nestedArray.add(1);
|
||||
nestedArray.add(2);
|
||||
REQUIRE(doc.as<std::string>() == "[[1,2]]");
|
||||
}
|
||||
|
||||
SECTION("add<JsonObject>()") {
|
||||
JsonObject nestedObject = array.add<JsonObject>();
|
||||
nestedObject["a"] = 1;
|
||||
nestedObject["b"] = 2;
|
||||
REQUIRE(doc.as<std::string>() == "[{\"a\":1,\"b\":2}]");
|
||||
}
|
||||
|
||||
SECTION("add<JsonVariant>()") {
|
||||
JsonVariant nestedVariant = array.add<JsonVariant>();
|
||||
nestedVariant.set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[42]");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user