add regression test #2824

parent a5633380
...@@ -157,6 +157,26 @@ struct adl_serializer<NonDefaultConstructible> ...@@ -157,6 +157,26 @@ struct adl_serializer<NonDefaultConstructible>
}; };
} // namespace nlohmann } // namespace nlohmann
/////////////////////////////////////////////////////////////////////
// for #2824
/////////////////////////////////////////////////////////////////////
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
{
public:
explicit sax_no_exception(json& j) : nlohmann::detail::json_sax_dom_parser<json>(j, false) {}
static bool parse_error(std::size_t position, const std::string& last_token, const json::exception& ex)
{
error_string = ex.what();
return false;
}
static std::string error_string;
};
std::string sax_no_exception::error_string = "";
TEST_CASE("regression tests 2") TEST_CASE("regression tests 2")
{ {
...@@ -622,6 +642,15 @@ TEST_CASE("regression tests 2") ...@@ -622,6 +642,15 @@ TEST_CASE("regression tests 2")
} }
} }
SECTION("issue #2824 - encoding of json::exception::what()")
{
json j;
sax_no_exception sax(j);
CHECK (!json::sax_parse("xyz", &sax));
CHECK(sax_no_exception::error_string == "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
}
SECTION("issue #2825 - Properly constrain the basic_json conversion operator") SECTION("issue #2825 - Properly constrain the basic_json conversion operator")
{ {
static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, ""); static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, "");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment