containsKey.cpp 1.1 KB

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