Added operators == and != for MemberProxy

This commit is contained in:
Benoit Blanchon
2019-07-19 10:21:58 +02:00
parent aba42faf69
commit 7ce1039d7c
4 changed files with 36 additions and 1 deletions

View File

@ -4,7 +4,7 @@ ArduinoJson: change log
HEAD HEAD
---- ----
* Added operators `==` and `!=` for `JsonDocument` * Added operators `==` and `!=` for `JsonDocument` and `MemberProxy`
v6.11.2 (2019-07-08) v6.11.2 (2019-07-08)
------- -------

View File

@ -49,6 +49,14 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
return *this; return *this;
} }
FORCE_INLINE bool operator==(VariantConstRef rhs) const {
return static_cast<VariantConstRef>(getUpstreamMember()) == rhs;
}
FORCE_INLINE bool operator!=(VariantConstRef rhs) const {
return static_cast<VariantConstRef>(getUpstreamMember()) != rhs;
}
FORCE_INLINE void clear() const { FORCE_INLINE void clear() const {
getUpstreamMember().clear(); getUpstreamMember().clear();
} }

View File

@ -5,6 +5,7 @@
add_executable(MemberProxyTests add_executable(MemberProxyTests
add.cpp add.cpp
clear.cpp clear.cpp
compare.cpp
containsKey.cpp containsKey.cpp
remove.cpp remove.cpp
set.cpp set.cpp

View File

@ -0,0 +1,26 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("MemberProxy::operator==()") {
DynamicJsonDocument doc(4096);
SECTION("same values") {
doc["key1"] = "value";
doc["key2"] = "value";
REQUIRE(doc["key1"] == doc["key2"]);
REQUIRE_FALSE(doc["key1"] != doc["key2"]);
}
SECTION("different values") {
doc["key1"] = "value1";
doc["key2"] = "value2";
REQUIRE_FALSE(doc["key1"] == doc["key2"]);
REQUIRE(doc["key1"] != doc["key2"]);
}
}