mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
remove()
This commit is contained in:
@@ -39,7 +39,7 @@ TEST_CASE("JsonVariant::memoryUsage()") {
|
|||||||
REQUIRE(var.memoryUsage() == doc.memoryUsage());
|
REQUIRE(var.memoryUsage() == doc.memoryUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ignore size of link document") {
|
SECTION("ignore size of linked document") {
|
||||||
StaticJsonDocument<128> doc2;
|
StaticJsonDocument<128> doc2;
|
||||||
doc2["hello"] = "world";
|
doc2["hello"] = "world";
|
||||||
var.link(doc2);
|
var.link(doc2);
|
||||||
|
|||||||
@@ -39,4 +39,24 @@ TEST_CASE("JsonVariant::remove()") {
|
|||||||
|
|
||||||
REQUIRE(var.as<std::string>() == "{\"a\":1}");
|
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\"}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,13 +177,13 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void remove(size_t index) {
|
void remove(size_t index) {
|
||||||
if (isArray())
|
if (isArrayStrict())
|
||||||
_content.asCollection.removeElement(index);
|
_content.asCollection.removeElement(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
template <typename TAdaptedString>
|
||||||
void remove(TAdaptedString key) {
|
void remove(TAdaptedString key) {
|
||||||
if (isObject())
|
if (isObjectStrict())
|
||||||
_content.asCollection.removeMember(key);
|
_content.asCollection.removeMember(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user