Files
ArduinoJson/extras/tests/JsonArray/clear.cpp

26 lines
577 B
C++
Raw Normal View History

2021-06-26 11:23:40 +02:00
// ArduinoJson - https://arduinojson.org
2023-02-16 11:45:01 +01:00
// Copyright © 2014-2023, Benoit BLANCHON
2021-06-26 11:23:40 +02:00
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonArray::clear()") {
SECTION("No-op on null JsonArray") {
JsonArray array;
array.clear();
REQUIRE(array.isNull() == true);
REQUIRE(array.size() == 0);
}
SECTION("Removes all elements") {
2023-03-15 14:54:55 +01:00
DynamicJsonDocument doc(64);
2021-06-26 11:23:40 +02:00
JsonArray array = doc.to<JsonArray>();
array.add(1);
array.add(2);
array.clear();
REQUIRE(array.size() == 0);
REQUIRE(array.isNull() == false);
}
}