diff options
author | Jay Berkenbilt <ejb@ql.org> | 2024-01-10 02:28:28 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2024-01-11 12:13:57 +0100 |
commit | 7de0b3f3c083990842523112959f8e27a0d2e5a0 (patch) | |
tree | e4bba51e3129c2a1b558b6a1cce0e2cf4e4c6974 /libtests | |
parent | 12f7a4461b18b4be94002fa0043fd0e98e80a274 (diff) | |
download | qpdf-7de0b3f3c083990842523112959f8e27a0d2e5a0.tar.zst |
JSONHandler: add fallback handler support
Diffstat (limited to 'libtests')
-rw-r--r-- | libtests/json_handler.cc | 6 | ||||
-rw-r--r-- | libtests/qtest/json_handler/json_handler.out | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/libtests/json_handler.cc b/libtests/json_handler.cc index 57185c98..2d3f9862 100644 --- a/libtests/json_handler.cc +++ b/libtests/json_handler.cc @@ -77,6 +77,7 @@ make_all_handler() auto h5s = std::make_shared<JSONHandler>(); h->addDictKeyHandler("five", h5s); h5s->addArrayHandlers(print_json, make_print_message("array end"), h5); + h5s->addFallbackHandler(h5); auto h6 = std::make_shared<JSONHandler>(); h6->addDictHandlers(print_json, make_print_message("dict end")); auto h6a = std::make_shared<JSONHandler>(); @@ -109,6 +110,11 @@ test_all() "six": {"a": {"b": "quack", "Q": "baaa"}, "b": "moo"} })"); h->handle(".", j); + std::cerr << "-- fallback --" << std::endl; + j = JSON::parse(R"({ + "five": "not-array" +})"); + h->handle(".", j); } static void diff --git a/libtests/qtest/json_handler/json_handler.out b/libtests/qtest/json_handler/json_handler.out index f076d4ee..4f340b85 100644 --- a/libtests/qtest/json_handler/json_handler.out +++ b/libtests/qtest/json_handler/json_handler.out @@ -63,6 +63,12 @@ .three: bool: true .two: number: 3.14 .: json: dict end +-- fallback -- +.: json: { + "five": "not-array" +} +.five: string: not-array +.: json: dict end -- errors -- bad type at top: JSON handler: value at . is not of expected type .: json: { |