Files
ArduinoJson/test/JsonArray/std_string.cpp
Benoit Blanchon 1a4515c0b9 Removed JsonArray::is<T>(i) and JsonArray::set(i,v)
Removed `JsonObject::is<T>(k)` and `JsonObject::set(k,v)`
Replaced `T JsonArray::get<T>(i)` with `JsonVariant JsonArray::get(i)`
Replaced `T JsonObject::get<T>(k)` with `JsonVariant JsonObject::get(k)`
2018-10-18 14:51:02 +02:00

32 lines
680 B
C++

// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
static void eraseString(std::string &str) {
char *p = const_cast<char *>(str.c_str());
while (*p) *p++ = '*';
}
TEST_CASE("std::string") {
DynamicJsonDocument doc;
JsonArray array = doc.to<JsonArray>();
SECTION("add()") {
std::string value("hello");
array.add(value);
eraseString(value);
REQUIRE(std::string("hello") == array[0]);
}
SECTION("operator[]") {
std::string value("world");
array.add("hello");
array[0] = value;
eraseString(value);
REQUIRE(std::string("world") == array[0]);
}
}