mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 02:36:18 +08:00
Test for JSON & CBOR encoding error handling (#432)
This commit is contained in:
@@ -15,7 +15,7 @@ struct Person {
|
||||
std::vector<Person> children;
|
||||
};
|
||||
|
||||
TEST(json, test_error_messages) {
|
||||
TEST(json, test_field_error_messages) {
|
||||
const std::string faulty_string =
|
||||
R"({"firstName":"Homer","lastName":12345,"birthday":"04/19/1987"})";
|
||||
|
||||
@@ -30,4 +30,20 @@ TEST(json, test_error_messages) {
|
||||
|
||||
EXPECT_EQ(result.error().what(), expected);
|
||||
}
|
||||
|
||||
TEST(json, test_decode_error_without_exception) {
|
||||
// Note using valid field names, but invalid JSON delimiter ';'
|
||||
const std::string faulty_string =
|
||||
R"({"firstName":"Homer";"lastName":"Simpson";"birthday":"1987-04-19"})";
|
||||
|
||||
rfl::Result<Person> result = rfl::error("result didn't get set");
|
||||
EXPECT_NO_THROW({
|
||||
result = rfl::json::read<Person>(faulty_string);
|
||||
});
|
||||
|
||||
EXPECT_TRUE(!result.has_value() && true);
|
||||
|
||||
EXPECT_EQ(result.error().what(), "Could not parse document");
|
||||
}
|
||||
|
||||
} // namespace test_error_messages
|
||||
|
||||
Reference in New Issue
Block a user