containsKey.cpp 842 B

123456789101112131415161718192021222324252627282930313233343536
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <stdint.h>
  6. #include <catch.hpp>
  7. #include "Literals.hpp"
  8. TEST_CASE("JsonVariant::containsKey()") {
  9. JsonDocument doc;
  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("hello"_s) == true);
  19. REQUIRE(var.containsKey("world"_s) == false);
  20. }
  21. SECTION("containsKey(JsonVariant)") {
  22. var["hello"] = "world";
  23. var["key"] = "hello";
  24. REQUIRE(var.containsKey(doc["key"]) == true);
  25. REQUIRE(var.containsKey(doc["foo"]) == false);
  26. }
  27. }