Add more tests for JsonObjectConst

This commit is contained in:
Benoit Blanchon
2024-01-08 18:48:11 +01:00
parent 44d2d47863
commit 08cac13c43
15 changed files with 281 additions and 89 deletions

View File

@ -5,8 +5,6 @@
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace Catch::Matchers;
TEST_CASE("JsonObject::begin()/end()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
@ -36,38 +34,3 @@ TEST_CASE("JsonObject::begin()/end()") {
REQUIRE(null.begin() == null.end());
}
}
TEST_CASE("JsonObjectConst::begin()/end()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
obj["ab"] = 12;
obj["cd"] = 34;
JsonObjectConst cobj = obj;
SECTION("Iteration") {
JsonObjectConst::iterator it = cobj.begin();
REQUIRE(cobj.end() != it);
REQUIRE(it->key() == "ab");
REQUIRE(12 == it->value());
++it;
REQUIRE(cobj.end() != it);
JsonPairConst pair = *it;
REQUIRE(pair.key() == "cd");
REQUIRE(34 == pair.value());
++it;
REQUIRE(cobj.end() == it);
}
SECTION("Dereferencing end() is safe") {
REQUIRE(cobj.end()->key().isNull());
REQUIRE(cobj.end()->value().isNull());
}
SECTION("null JsonObjectConst") {
JsonObjectConst null;
REQUIRE(null.begin() == null.end());
}
}