or.cpp 721 B

1234567891011121314151617181920212223242526272829
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2020
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("MemberProxy::operator|()") {
  8. DynamicJsonDocument doc(4096);
  9. SECTION("const char*") {
  10. doc["a"] = "hello";
  11. REQUIRE((doc["a"] | "world") == std::string("hello"));
  12. REQUIRE((doc["b"] | "world") == std::string("world"));
  13. }
  14. SECTION("Issue #1411") {
  15. doc["sensor"] = "gps";
  16. const char *test = "test"; // <- the literal must be captured in a variable
  17. // to trigger the bug
  18. const char *sensor = doc["sensor"] | test; // "gps"
  19. REQUIRE(sensor == std::string("gps"));
  20. }
  21. }