This commit is contained in:
Benoit Blanchon
2022-03-13 20:51:13 +01:00
parent a4307f5cd1
commit c68bd7fb95
3 changed files with 23 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ TEST_CASE("JsonVariant::memoryUsage()") {
REQUIRE(var.memoryUsage() == doc.memoryUsage());
}
SECTION("ignore size of link document") {
SECTION("ignore size of linked document") {
StaticJsonDocument<128> doc2;
doc2["hello"] = "world";
var.link(doc2);

View File

@@ -39,4 +39,24 @@ TEST_CASE("JsonVariant::remove()") {
REQUIRE(var.as<std::string>() == "{\"a\":1}");
}
SECTION("linked array") {
StaticJsonDocument<128> doc2;
doc2[0] = 42;
var.link(doc2);
var.remove(0);
CHECK(var.as<std::string>() == "[42]");
}
SECTION("linked object") {
StaticJsonDocument<128> doc2;
doc2["hello"] = "world";
var.link(doc2);
var.remove("hello");
CHECK(var.as<std::string>() == "{\"hello\":\"world\"}");
}
}

View File

@@ -177,13 +177,13 @@ class VariantData {
}
void remove(size_t index) {
if (isArray())
if (isArrayStrict())
_content.asCollection.removeElement(index);
}
template <typename TAdaptedString>
void remove(TAdaptedString key) {
if (isObject())
if (isObjectStrict())
_content.asCollection.removeMember(key);
}