arduino/libraries/ArduinoJson/test/JsonObject/size.cpp

40 lines
857 B
C++
Raw Normal View History

2018-11-03 20:21:33 +00:00
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
#include <string>
TEST_CASE("JsonObject::size()") {
DynamicJsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
SECTION("initial size is zero") {
REQUIRE(0 == obj.size());
}
SECTION("increases when values are added") {
obj.set("hello", 42);
REQUIRE(1 == obj.size());
}
2018-11-13 14:50:48 +00:00
SECTION("decreases when values are removed") {
obj.set("hello", 42);
obj.remove("hello");
REQUIRE(0 == obj.size());
}
SECTION("doesn't increase when the same key is added twice") {
2018-11-03 20:21:33 +00:00
obj["hello"] = 1;
obj["hello"] = 2;
REQUIRE(1 == obj.size());
}
2018-11-13 14:50:48 +00:00
SECTION("doesn't decrease when another key is removed") {
obj["hello"] = 1;
obj.remove("world");
REQUIRE(1 == obj.size());
}
2018-11-03 20:21:33 +00:00
}