Added operator|(JsonVariantConst, JsonVariantConst)

This commit is contained in:
Benoit Blanchon
2020-09-26 14:48:17 +02:00
parent fee029b86e
commit 726f8be341
4 changed files with 61 additions and 4 deletions

View File

@ -7,7 +7,7 @@
TEST_CASE("JsonVariant::operator|()") {
DynamicJsonDocument doc(4096);
JsonVariant variant = doc.to<JsonVariant>();
JsonVariant variant = doc["value"].to<JsonVariant>();
SECTION("undefined") {
SECTION("undefined | const char*") {
@ -24,6 +24,27 @@ TEST_CASE("JsonVariant::operator|()") {
bool result = variant | true;
REQUIRE(result == true);
}
SECTION("undefined | ElementProxy") {
doc["array"][0] = 42;
JsonVariantConst result = variant | doc["array"][0];
REQUIRE(result == 42);
}
SECTION("undefined | MemberProxy") {
doc["other"] = 42;
JsonVariantConst result = variant | doc["other"];
REQUIRE(result == 42);
}
SECTION("ElementProxy | ElementProxy") {
doc["array"][0] = 42;
JsonVariantConst result = doc["array"][1] | doc["array"][0];
REQUIRE(result == 42);
}
}
SECTION("null") {
@ -43,6 +64,20 @@ TEST_CASE("JsonVariant::operator|()") {
bool result = variant | true;
REQUIRE(result == true);
}
SECTION("null | ElementProxy") {
doc["array"][0] = 42;
JsonVariantConst result = variant | doc["array"][0];
REQUIRE(result == 42);
}
SECTION("null | MemberProxy") {
doc["other"] = 42;
JsonVariantConst result = variant | doc["other"];
REQUIRE(result == 42);
}
}
SECTION("int | const char*") {
@ -57,6 +92,20 @@ TEST_CASE("JsonVariant::operator|()") {
REQUIRE(result == 42);
}
SECTION("int | ElementProxy") {
variant.set(42);
doc["array"][0] = 666;
JsonVariantConst result = variant | doc["array"][0];
REQUIRE(result == 42);
}
SECTION("int | MemberProxy") {
variant.set(42);
doc["other"] = 666;
JsonVariantConst result = variant | doc["other"];
REQUIRE(result == 42);
}
SECTION("int | int") {
variant.set(0);
int result = variant | 666;