containsKey.cpp 785 B

123456789101112131415161718192021222324252627282930313233
  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. TEST_CASE("JsonVariantConst::containsKey()") {
  8. JsonDocument doc;
  9. doc["hello"] = "world";
  10. JsonVariantConst var = doc.as<JsonVariant>();
  11. SECTION("support const char*") {
  12. REQUIRE(var.containsKey("hello") == true);
  13. REQUIRE(var.containsKey("world") == false);
  14. }
  15. SECTION("support std::string") {
  16. REQUIRE(var.containsKey(std::string("hello")) == true);
  17. REQUIRE(var.containsKey(std::string("world")) == false);
  18. }
  19. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  20. SECTION("supports VLA") {
  21. size_t i = 16;
  22. char vla[i];
  23. strcpy(vla, "hello");
  24. REQUIRE(true == var.containsKey(vla));
  25. }
  26. #endif
  27. }