containsKey.cpp 800 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://bblanchon.github.io/ArduinoJson/
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson.h>
  8. #include <catch.hpp>
  9. TEST_CASE("JsonObject::containsKey()") {
  10. DynamicJsonBuffer _jsonBuffer;
  11. JsonObject& _object = _jsonBuffer.createObject();
  12. SECTION("ContainsKeyReturnsFalseForNonExistingKey") {
  13. _object.set("hello", 42);
  14. REQUIRE(false == _object.containsKey("world"));
  15. }
  16. SECTION("ContainsKeyReturnsTrueForDefinedValue") {
  17. _object.set("hello", 42);
  18. REQUIRE(true == _object.containsKey("hello"));
  19. }
  20. SECTION("ContainsKeyReturnsFalseAfterRemove") {
  21. _object.set("hello", 42);
  22. _object.remove("hello");
  23. REQUIRE(false == _object.containsKey("hello"));
  24. }
  25. }