2024-01-08 19:31:29 +01:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
|
|
|
// Copyright © 2014-2024, Benoit BLANCHON
|
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
2024-06-07 09:35:45 +02:00
|
|
|
#include "Literals.hpp"
|
|
|
|
|
2024-01-08 19:31:29 +01:00
|
|
|
TEST_CASE("JsonVariantConst::containsKey()") {
|
|
|
|
JsonDocument doc;
|
|
|
|
doc["hello"] = "world";
|
|
|
|
JsonVariantConst var = doc.as<JsonVariant>();
|
|
|
|
|
|
|
|
SECTION("support const char*") {
|
|
|
|
REQUIRE(var.containsKey("hello") == true);
|
|
|
|
REQUIRE(var.containsKey("world") == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("support std::string") {
|
2024-06-07 09:35:45 +02:00
|
|
|
REQUIRE(var.containsKey("hello"_s) == true);
|
|
|
|
REQUIRE(var.containsKey("world"_s) == false);
|
2024-01-08 19:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
|
|
|
SECTION("supports VLA") {
|
|
|
|
size_t i = 16;
|
|
|
|
char vla[i];
|
|
|
|
strcpy(vla, "hello");
|
|
|
|
|
|
|
|
REQUIRE(true == var.containsKey(vla));
|
|
|
|
}
|
|
|
|
#endif
|
2024-05-14 21:06:02 +02:00
|
|
|
|
|
|
|
SECTION("support JsonVariant") {
|
|
|
|
doc["key"] = "hello";
|
|
|
|
REQUIRE(var.containsKey(var["key"]) == true);
|
|
|
|
REQUIRE(var.containsKey(var["foo"]) == false);
|
|
|
|
}
|
2024-01-08 19:31:29 +01:00
|
|
|
}
|