mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 04:22:18 +02:00
Tests: add user-defined literal ""_s
for std::string
This commit is contained in:
@ -7,6 +7,8 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
#define SHOULD_WORK(expression) REQUIRE(DeserializationError::Ok == expression);
|
||||
#define SHOULD_FAIL(expression) \
|
||||
REQUIRE(DeserializationError::TooDeep == expression);
|
||||
@ -63,23 +65,23 @@ TEST_CASE("JsonDeserializer nesting") {
|
||||
SECTION("Input = std::string") {
|
||||
SECTION("limit = 0") {
|
||||
DeserializationOption::NestingLimit nesting(0);
|
||||
SHOULD_WORK(deserializeJson(doc, std::string("\"toto\""), nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, std::string("123"), nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, std::string("true"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("[]"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("{}"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("[\"toto\"]"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":1}"), nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, "\"toto\""_s, nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, "123"_s, nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, "true"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "[]"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "{}"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "[\"toto\"]"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "{\"toto\":1}"_s, nesting));
|
||||
}
|
||||
|
||||
SECTION("limit = 1") {
|
||||
DeserializationOption::NestingLimit nesting(1);
|
||||
SHOULD_WORK(deserializeJson(doc, std::string("[\"toto\"]"), nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, std::string("{\"toto\":1}"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":{}}"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":[]}"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("[[\"toto\"]]"), nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, std::string("[{\"toto\":1}]"), nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, "[\"toto\"]"_s, nesting));
|
||||
SHOULD_WORK(deserializeJson(doc, "{\"toto\":1}"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "{\"toto\":{}}"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "{\"toto\":[]}"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "[[\"toto\"]]"_s, nesting));
|
||||
SHOULD_FAIL(deserializeJson(doc, "[{\"toto\":1}]"_s, nesting));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user