forked from bblanchon/ArduinoJson
Test custom converter for char
(#1963)
This commit is contained in:
@ -158,6 +158,11 @@ void convertToJson(char c, JsonVariant var) {
|
|||||||
char buf[] = {c, 0};
|
char buf[] = {c, 0};
|
||||||
var.set(buf);
|
var.set(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void convertFromJson(JsonVariantConst src, char& dst) {
|
||||||
|
auto p = src.as<const char*>();
|
||||||
|
dst = p ? p[0] : 0;
|
||||||
|
}
|
||||||
} // namespace ArduinoJson
|
} // namespace ArduinoJson
|
||||||
|
|
||||||
TEST_CASE("Convert char to string") { // issue #1922
|
TEST_CASE("Convert char to string") { // issue #1922
|
||||||
@ -165,3 +170,9 @@ TEST_CASE("Convert char to string") { // issue #1922
|
|||||||
doc.set('a');
|
doc.set('a');
|
||||||
REQUIRE(doc.as<std::string>() == "a");
|
REQUIRE(doc.as<std::string>() == "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Convert string to char") { // issue #1963
|
||||||
|
StaticJsonDocument<64> doc;
|
||||||
|
doc.set("a");
|
||||||
|
REQUIRE(doc.as<char>() == 'a');
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user