Files
ArduinoJson/extras/tests/JsonVariant/containsKey.cpp

37 lines
842 B
C++
Raw Normal View History

// ArduinoJson - https://arduinojson.org
2024-01-03 08:47:06 +01:00
// Copyright © 2014-2024, Benoit BLANCHON
2019-03-22 09:00:00 +01:00
// MIT License
#include <ArduinoJson.h>
#include <stdint.h>
#include <catch.hpp>
#include "Literals.hpp"
2019-03-22 09:00:00 +01:00
TEST_CASE("JsonVariant::containsKey()") {
JsonDocument doc;
2019-03-22 09:00:00 +01:00
JsonVariant var = doc.to<JsonVariant>();
SECTION("containsKey(const char*)") {
2019-03-22 09:00:00 +01:00
var["hello"] = "world";
REQUIRE(var.containsKey("hello") == true);
REQUIRE(var.containsKey("world") == false);
}
SECTION("containsKey(std::string)") {
2019-03-22 09:00:00 +01:00
var["hello"] = "world";
REQUIRE(var.containsKey("hello"_s) == true);
REQUIRE(var.containsKey("world"_s) == false);
2019-03-22 09:00:00 +01:00
}
SECTION("containsKey(JsonVariant)") {
var["hello"] = "world";
var["key"] = "hello";
REQUIRE(var.containsKey(doc["key"]) == true);
REQUIRE(var.containsKey(doc["foo"]) == false);
}
2019-03-22 09:00:00 +01:00
}