Improved coverage of JsonObject

This commit is contained in:
Benoit Blanchon
2020-02-23 13:03:14 +01:00
parent a471aed6db
commit 0214c9bcad
4 changed files with 47 additions and 0 deletions

View File

@ -94,4 +94,22 @@ TEST_CASE("JsonObject::set()") {
REQUIRE(success == false);
REQUIRE(doc3.as<std::string>() == "{\"hello\":null}");
}
SECTION("destination is null") {
JsonObject null;
obj1["hello"] = "world";
bool success = null.set(obj1);
REQUIRE(success == false);
}
SECTION("source is null") {
JsonObject null;
obj1["hello"] = "world";
bool success = obj1.set(null);
REQUIRE(success == false);
}
}

View File

@ -50,4 +50,18 @@ TEST_CASE("JsonObject::operator==()") {
REQUIRE(obj1 == obj2);
REQUIRE(obj1c == obj2c);
}
SECTION("should return false when RHS is null") {
JsonObject null;
REQUIRE_FALSE(obj1 == null);
REQUIRE_FALSE(obj1c == null);
}
SECTION("should return false when LHS is null") {
JsonObject null;
REQUIRE_FALSE(null == obj2);
REQUIRE_FALSE(null == obj2c);
}
}

View File

@ -30,6 +30,11 @@ TEST_CASE("JsonObject::begin()/end()") {
REQUIRE(obj.end()->key().isNull());
REQUIRE(obj.end()->value().isNull());
}
SECTION("null JsonObject") {
JsonObject null;
REQUIRE(null.begin() == null.end());
}
}
TEST_CASE("JsonObjectConst::begin()/end()") {
@ -60,4 +65,9 @@ TEST_CASE("JsonObjectConst::begin()/end()") {
REQUIRE(cobj.end()->key().isNull());
REQUIRE(cobj.end()->value().isNull());
}
SECTION("null JsonObjectConst") {
JsonObjectConst null;
REQUIRE(null.begin() == null.end());
}
}

View File

@ -69,4 +69,9 @@ TEST_CASE("JsonObject::remove()") {
REQUIRE("{\"a\":0,\"c\":2}" == result);
}
#endif
SECTION("should work on null object") {
JsonObject null;
null.remove("key");
}
}