mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Fix comparisons operators with const JsonDocument&
This commit is contained in:
@ -7,6 +7,7 @@ HEAD
|
||||
* Add `ElementProxy::memoryUsage()`
|
||||
* Add `MemberProxy::memoryUsage()` (issue #1730)
|
||||
* Add implicit conversion from `JsonDocument` to `JsonVariant`
|
||||
* Fix comparisons operators with `const JsonDocument&`
|
||||
|
||||
v6.19.3 (2022-03-08)
|
||||
-------
|
||||
|
@ -75,3 +75,29 @@ TEST_CASE("StaticJsonDocument::operator==(const DynamicJsonDocument&)") {
|
||||
REQUIRE(doc1 != doc2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonDocument::operator==(const JsonDocument&)") {
|
||||
StaticJsonDocument<256> doc1;
|
||||
StaticJsonDocument<256> doc2;
|
||||
const JsonDocument& ref1 = doc1;
|
||||
const JsonDocument& ref2 = doc2;
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(ref1 == ref2);
|
||||
REQUIRE_FALSE(ref1 != ref2);
|
||||
}
|
||||
|
||||
SECTION("With same object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["hello"] = "world";
|
||||
REQUIRE(ref1 == ref2);
|
||||
REQUIRE_FALSE(ref1 != ref2);
|
||||
}
|
||||
|
||||
SECTION("With different object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["world"] = "hello";
|
||||
REQUIRE_FALSE(ref1 == ref2);
|
||||
REQUIRE(ref1 != ref2);
|
||||
}
|
||||
}
|
||||
|
@ -131,9 +131,9 @@ struct RawComparer : ComparerBase {
|
||||
template <typename T>
|
||||
struct Comparer<T, typename enable_if<IsVisitable<T>::value>::type>
|
||||
: ComparerBase {
|
||||
T rhs;
|
||||
const T *rhs; // TODO: should be a VariantConstRef
|
||||
|
||||
explicit Comparer(T value) : rhs(value) {}
|
||||
explicit Comparer(const T &value) : rhs(&value) {}
|
||||
|
||||
CompareResult visitArray(const CollectionData &lhs) {
|
||||
ArrayComparer comparer(lhs);
|
||||
@ -183,7 +183,7 @@ struct Comparer<T, typename enable_if<IsVisitable<T>::value>::type>
|
||||
private:
|
||||
template <typename TComparer>
|
||||
CompareResult accept(TComparer &comparer) {
|
||||
CompareResult reversedResult = rhs.accept(comparer);
|
||||
CompareResult reversedResult = rhs->accept(comparer);
|
||||
switch (reversedResult) {
|
||||
case COMPARE_RESULT_GREATER:
|
||||
return COMPARE_RESULT_LESS;
|
||||
|
Reference in New Issue
Block a user