containsKey.cpp 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonDocument::containsKey()") {
  7. DynamicJsonDocument doc(4096);
  8. SECTION("returns true on object") {
  9. doc["hello"] = "world";
  10. REQUIRE(doc.containsKey("hello") == true);
  11. }
  12. SECTION("returns true when value is null") {
  13. doc["hello"] = static_cast<const char*>(0);
  14. REQUIRE(doc.containsKey("hello") == true);
  15. }
  16. SECTION("returns true when key is a std::string") {
  17. doc["hello"] = "world";
  18. REQUIRE(doc.containsKey(std::string("hello")) == true);
  19. }
  20. SECTION("returns false on object") {
  21. doc["world"] = "hello";
  22. REQUIRE(doc.containsKey("hello") == false);
  23. }
  24. SECTION("returns false on array") {
  25. doc.add("hello");
  26. REQUIRE(doc.containsKey("hello") == false);
  27. }
  28. SECTION("returns false on null") {
  29. REQUIRE(doc.containsKey("hello") == false);
  30. }
  31. }