mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 12:32:17 +02:00
Added JsonObject::containsKey()
This commit is contained in:
@ -78,6 +78,9 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
|
||||
// This is a shortcut for JsonBuffer::createObject() and JsonObject::add().
|
||||
JsonObject &createNestedObject(key_type key);
|
||||
|
||||
// Tells weither the specified key is present and associated with a value.
|
||||
bool containsKey(key_type key) const { return at(key).success(); }
|
||||
|
||||
// Removes the specified key and the associated value.
|
||||
void remove(key_type key);
|
||||
|
||||
|
@ -38,7 +38,7 @@ class JsonVariant : public Internals::JsonPrintable<JsonVariant> {
|
||||
}
|
||||
|
||||
// Tells weither the variant is valid.
|
||||
bool success() {
|
||||
bool success() const {
|
||||
return _type != Internals::JSON_INVALID &&
|
||||
_type != Internals::JSON_UNDEFINED;
|
||||
}
|
||||
|
@ -114,3 +114,17 @@ TEST_F(JsonObject_Container_Tests, CanStoreInnerObjects) {
|
||||
EXPECT_EQ(&innerObject1, &object["hello"].asObject());
|
||||
EXPECT_EQ(&innerObject2, &object["world"].asObject());
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_Container_Tests, ContainsKeyReturnFalseForNonExistingKey) {
|
||||
EXPECT_FALSE(object.containsKey("hello"));
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_Container_Tests, ContainsKeyReturnTrueForDefinedValue) {
|
||||
object.add("hello", 42);
|
||||
EXPECT_TRUE(object.containsKey("hello"));
|
||||
}
|
||||
|
||||
TEST_F(JsonObject_Container_Tests, ContainsKeyReturnFalseForUndefinedValue) {
|
||||
object.add("hello");
|
||||
EXPECT_FALSE(object.containsKey("hello"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user