containsKey.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2023, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <stdint.h>
  6. #include <catch.hpp>
  7. TEST_CASE("JsonVariant::containsKey()") {
  8. DynamicJsonDocument doc(4096);
  9. JsonVariant var = doc.to<JsonVariant>();
  10. SECTION("containsKey(const char*)") {
  11. var["hello"] = "world";
  12. REQUIRE(var.containsKey("hello") == true);
  13. REQUIRE(var.containsKey("world") == false);
  14. }
  15. SECTION("containsKey(std::string)") {
  16. var["hello"] = "world";
  17. REQUIRE(var.containsKey(std::string("hello")) == true);
  18. REQUIRE(var.containsKey(std::string("world")) == false);
  19. }
  20. }
  21. TEST_CASE("JsonVariantConst::containsKey()") {
  22. DynamicJsonDocument doc(4096);
  23. doc["hello"] = "world";
  24. JsonVariantConst cvar = doc.as<JsonVariant>();
  25. SECTION("containsKey(const char*) returns true") {
  26. REQUIRE(cvar.containsKey("hello") == true);
  27. REQUIRE(cvar.containsKey("world") == false);
  28. }
  29. SECTION("containsKey(std::string) returns true") {
  30. REQUIRE(cvar.containsKey(std::string("hello")) == true);
  31. REQUIRE(cvar.containsKey(std::string("world")) == false);
  32. }
  33. }