Test for JSON & CBOR encoding error handling (#432)

This commit is contained in:
Bryce Schober
2025-05-14 22:06:36 +08:00
committed by GitHub
parent 778cd54173
commit b6446a8be4
5 changed files with 169 additions and 13 deletions
+17 -1
View File
@@ -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