Added JsonDocument::operator[]

This commit is contained in:
Benoit Blanchon committed 2019-01-23 11:43:29 +01:00
1 parent 4167b11434
commit 933a66a070
5 files changed
+86 -12

No files matched your search

+1
View File
@@ -7,6 +7,7 @@ add_executable(JsonDocumentTests
nesting.cpp
isNull.cpp
StaticJsonDocument.cpp
subscript.cpp
)
target_link_libraries(JsonDocumentTests catch)
+32
View File
@@ -0,0 +1,32 @@
// 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");
}
}