as<bool>()

This commit is contained in:
Benoit Blanchon
2022-03-11 18:54:51 +01:00
parent 8b1d38f92a
commit a4307f5cd1
2 changed files with 13 additions and 0 deletions

View File

@@ -349,4 +349,15 @@ TEST_CASE("JsonVariant::as()") {
CHECK(variant.as<std::string>() == "hello");
}
SECTION("linked bool") {
StaticJsonDocument<128> doc2;
variant.link(doc2);
doc2.set(true);
CHECK(variant.as<bool>() == true);
doc2.set(false);
CHECK(variant.as<bool>() == false);
}
}

View File

@@ -47,6 +47,8 @@ inline bool VariantData::asBoolean() const {
return _content.asFloat != 0;
case VALUE_IS_NULL:
return false;
case VALUE_IS_POINTER:
return _content.asPointer->asBoolean();
default:
return true;
}