Files
ArduinoJson/extras/tests/JsonArray/size.cpp
T

32 lines
651 B
C++
Raw Normal View History

// ArduinoJson - https://arduinojson.org
2025-02-24 15:18:26 +01:00
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonArray::size()") {
JsonDocument doc;
2018-07-12 09:08:20 +02:00
JsonArray array = doc.to<JsonArray>();
SECTION("returns 0 is empty") {
2018-07-12 09:08:20 +02:00
REQUIRE(0U == array.size());
}
SECTION("increases after add()") {
2018-07-12 09:08:20 +02:00
array.add("hello");
REQUIRE(1U == array.size());
2018-07-12 09:08:20 +02:00
array.add("world");
REQUIRE(2U == array.size());
}
SECTION("remains the same after replacing an element") {
2018-07-12 09:08:20 +02:00
array.add("hello");
REQUIRE(1U == array.size());
2018-07-12 09:08:20 +02:00
array[0] = "hello";
REQUIRE(1U == array.size());
}
}