mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 02:56:35 +02:00
33 lines
725 B
C++
33 lines
725 B
C++
![]() |
// ArduinoJson - arduinojson.org
|
||
|
// Copyright Benoit Blanchon 2014-2018
|
||
|
// MIT License
|
||
|
|
||
|
#include <ArduinoJson.h>
|
||
|
#include <catch.hpp>
|
||
|
|
||
|
TEST_CASE("JsonDocument::operator[]") {
|
||
|
DynamicJsonDocument doc(4096);
|
||
|
const JsonDocument& cdoc = doc;
|
||
|
|
||
|
SECTION("object") {
|
||
|
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||
|
|
||
|
SECTION("const char*") {
|
||
|
REQUIRE(doc["hello"] == "world");
|
||
|
REQUIRE(cdoc["hello"] == "world");
|
||
|
}
|
||
|
|
||
|
SECTION("std::string") {
|
||
|
REQUIRE(doc[std::string("hello")] == "world");
|
||
|
REQUIRE(cdoc[std::string("hello")] == "world");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
SECTION("array") {
|
||
|
deserializeJson(doc, "[\"hello\",\"world\"]");
|
||
|
|
||
|
REQUIRE(doc[1] == "world");
|
||
|
REQUIRE(cdoc[1] == "world");
|
||
|
}
|
||
|
}
|