containsKey.cpp 753 B

1234567891011121314151617181920212223242526272829303132
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObjectConst::containsKey()") {
  7. JsonDocument doc;
  8. doc["hello"] = 42;
  9. auto obj = doc.as<JsonObjectConst>();
  10. SECTION("supports const char*") {
  11. REQUIRE(false == obj.containsKey("world"));
  12. REQUIRE(true == obj.containsKey("hello"));
  13. }
  14. SECTION("supports std::string") {
  15. REQUIRE(false == obj.containsKey(std::string("world")));
  16. REQUIRE(true == obj.containsKey(std::string("hello")));
  17. }
  18. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  19. SECTION("supports VLA") {
  20. size_t i = 16;
  21. char vla[i];
  22. strcpy(vla, "hello");
  23. REQUIRE(true == obj.containsKey(vla));
  24. }
  25. #endif
  26. }