|
|
@@ -63,13 +63,32 @@ void test_string_view_overload() {
|
|
|
}
|
|
|
|
|
|
void test_invalid_json_throws() {
|
|
|
+ // Contract: parse_to_nlohmann throws nlohmann::json::parse_error so the
|
|
|
+ // 17 downstream callsites that catch (nlohmann::json::parse_error&) keep
|
|
|
+ // working unchanged. Catching the specific type guards against a future
|
|
|
+ // refactor silently changing the throw type.
|
|
|
bool threw = false;
|
|
|
try {
|
|
|
(void)parse_to_nlohmann("{not json");
|
|
|
- } catch (const std::exception&) {
|
|
|
+ } catch (const nlohmann::json::parse_error&) {
|
|
|
threw = true;
|
|
|
}
|
|
|
- check(threw, "invalid json throws");
|
|
|
+ check(threw, "invalid json throws parse_error");
|
|
|
+}
|
|
|
+
|
|
|
+void test_empty_string_throws_parse_error() {
|
|
|
+ // After the v1.10 fix, empty input is no longer pre-rejected with a
|
|
|
+ // bespoke "empty input" message — it falls through to yyjson, which
|
|
|
+ // emits a positional "unexpected end of data" error wrapped in
|
|
|
+ // parse_error. Verifies the message-path consistency the reviewer asked
|
|
|
+ // for so that operators see the same error shape for empty vs. malformed.
|
|
|
+ bool threw = false;
|
|
|
+ try {
|
|
|
+ (void)parse_to_nlohmann("");
|
|
|
+ } catch (const nlohmann::json::parse_error&) {
|
|
|
+ threw = true;
|
|
|
+ }
|
|
|
+ check(threw, "empty string throws parse_error");
|
|
|
}
|
|
|
|
|
|
void test_corpus_equivalence() {
|
|
|
@@ -98,6 +117,7 @@ int main() {
|
|
|
test_large_int();
|
|
|
test_string_view_overload();
|
|
|
test_invalid_json_throws();
|
|
|
+ test_empty_string_throws_parse_error();
|
|
|
test_corpus_equivalence();
|
|
|
std::cout << "test_json_parse: all passed\n";
|
|
|
return 0;
|