mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-25 00:07:34 +02:00
Tests: add user-defined literal ""_s
for std::string
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
template <typename T>
|
||||
static void checkValue(const char* input, T expected) {
|
||||
@ -123,21 +124,21 @@ TEST_CASE("deserialize MsgPack value") {
|
||||
|
||||
SECTION("fixstr") {
|
||||
checkValue<std::string>("\xA0", std::string(""));
|
||||
checkValue<std::string>("\xABhello world", std::string("hello world"));
|
||||
checkValue<std::string>("\xABhello world", "hello world"_s);
|
||||
checkValue<std::string>("\xBFhello world hello world hello !",
|
||||
std::string("hello world hello world hello !"));
|
||||
"hello world hello world hello !"_s);
|
||||
}
|
||||
|
||||
SECTION("str 8") {
|
||||
checkValue<std::string>("\xd9\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xd9\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("str 16") {
|
||||
checkValue<std::string>("\xda\x00\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xda\x00\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("str 32") {
|
||||
checkValue<std::string>("\xdb\x00\x00\x00\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xdb\x00\x00\x00\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("bin 8") {
|
||||
@ -156,7 +157,7 @@ TEST_CASE("deserialize MsgPack value") {
|
||||
SECTION("bin 16") {
|
||||
JsonDocument doc;
|
||||
auto str = std::string(256, '?');
|
||||
auto input = std::string("\xc5\x01\x00", 3) + str;
|
||||
auto input = "\xc5\x01\x00"_s + str;
|
||||
|
||||
DeserializationError error = deserializeMsgPack(doc, input);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject;
|
||||
TEST_CASE("deserializeMsgPack(JsonDocument&)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
auto err = deserializeMsgPack(doc, "\x91\x2A");
|
||||
@ -34,7 +35,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
||||
SECTION("variant is bound") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
JsonVariant variant = doc[0];
|
||||
@ -60,7 +61,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
||||
TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
SECTION("element already exists") {
|
||||
@ -85,7 +86,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc[std::string("hello")] = std::string("world");
|
||||
doc["hello"_s] = "world"_s;
|
||||
spy.clearLog();
|
||||
|
||||
SECTION("member already exists") {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using namespace ArduinoJson::detail;
|
||||
|
||||
@ -1552,7 +1553,7 @@ TEST_CASE("Overloads") {
|
||||
}
|
||||
|
||||
SECTION("const std::string&, Filter") {
|
||||
deserializeMsgPack(doc, std::string("{}"), Filter(filter));
|
||||
deserializeMsgPack(doc, "{}"_s, Filter(filter));
|
||||
}
|
||||
|
||||
SECTION("std::istream&, Filter") {
|
||||
@ -1580,7 +1581,7 @@ TEST_CASE("Overloads") {
|
||||
}
|
||||
|
||||
SECTION("const std::string&, Filter, NestingLimit") {
|
||||
deserializeMsgPack(doc, std::string("{}"), Filter(filter), NestingLimit(5));
|
||||
deserializeMsgPack(doc, "{}"_s, Filter(filter), NestingLimit(5));
|
||||
}
|
||||
|
||||
SECTION("std::istream&, Filter, NestingLimit") {
|
||||
@ -1608,7 +1609,7 @@ TEST_CASE("Overloads") {
|
||||
}
|
||||
|
||||
SECTION("const std::string&, NestingLimit, Filter") {
|
||||
deserializeMsgPack(doc, std::string("{}"), NestingLimit(5), Filter(filter));
|
||||
deserializeMsgPack(doc, "{}"_s, NestingLimit(5), Filter(filter));
|
||||
}
|
||||
|
||||
SECTION("std::istream&, NestingLimit, Filter") {
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "CustomReader.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
|
||||
@ -21,8 +22,7 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
|
||||
}
|
||||
|
||||
SECTION("should accept temporary string") {
|
||||
DeserializationError err =
|
||||
deserializeMsgPack(doc, std::string("\x92\x01\x02"));
|
||||
DeserializationError err = deserializeMsgPack(doc, "\x92\x01\x02"_s);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
||||
@ -35,12 +35,11 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
|
||||
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(std::string("hello") == array[0]);
|
||||
REQUIRE("hello"_s == array[0]);
|
||||
}
|
||||
|
||||
SECTION("should accept a zero in input") {
|
||||
DeserializationError err =
|
||||
deserializeMsgPack(doc, std::string("\x92\x00\x02", 3));
|
||||
DeserializationError err = deserializeMsgPack(doc, "\x92\x00\x02"_s);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
JsonArray arr = doc.as<JsonArray>();
|
||||
@ -53,7 +52,7 @@ TEST_CASE("deserializeMsgPack(std::istream&)") {
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("should accept a zero in input") {
|
||||
std::istringstream input(std::string("\x92\x00\x02", 3));
|
||||
std::istringstream input("\x92\x00\x02"_s);
|
||||
|
||||
DeserializationError err = deserializeMsgPack(doc, input);
|
||||
|
||||
|
Reference in New Issue
Block a user