containsKey.cpp 670 B

123456789101112131415161718192021222324252627282930
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObject::containsKey()") {
  7. DynamicJsonDocument doc;
  8. JsonObject& obj = doc.to<JsonObject>();
  9. SECTION("ContainsKeyReturnsFalseForNonExistingKey") {
  10. obj.set("hello", 42);
  11. REQUIRE(false == obj.containsKey("world"));
  12. }
  13. SECTION("ContainsKeyReturnsTrueForDefinedValue") {
  14. obj.set("hello", 42);
  15. REQUIRE(true == obj.containsKey("hello"));
  16. }
  17. SECTION("ContainsKeyReturnsFalseAfterRemove") {
  18. obj.set("hello", 42);
  19. obj.remove("hello");
  20. REQUIRE(false == obj.containsKey("hello"));
  21. }
  22. }