containsKey.cpp 725 B

123456789101112131415161718192021222324252627282930313233
  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("JsonObject::containsKey()") {
  7. JsonDocument doc;
  8. JsonObject obj = doc.to<JsonObject>();
  9. obj["hello"] = 42;
  10. SECTION("returns true only if key is present") {
  11. REQUIRE(false == obj.containsKey("world"));
  12. REQUIRE(true == obj.containsKey("hello"));
  13. }
  14. SECTION("returns false after remove()") {
  15. obj.remove("hello");
  16. REQUIRE(false == obj.containsKey("hello"));
  17. }
  18. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  19. SECTION("key is a VLA") {
  20. size_t i = 16;
  21. char vla[i];
  22. strcpy(vla, "hello");
  23. REQUIRE(true == obj.containsKey(vla));
  24. }
  25. #endif
  26. }