@@ -24,6 +24,7 @@ using boost::redis::adapter::adapt2;
2424using boost::redis::adapter::result;
2525using boost::redis::resp3::tree;
2626using boost::redis::resp3::flat_tree;
27+ using boost::redis::generic_flat_response;
2728using boost::redis::ignore_t ;
2829using boost::redis::resp3::detail::deserialize;
2930using boost::redis::resp3::node;
@@ -375,25 +376,45 @@ tree from_flat(flat_tree const& resp)
375376 return ret;
376377}
377378
379+ tree from_flat (generic_flat_response const & resp)
380+ {
381+ tree ret;
382+ for (auto const & e: resp.value ().get_view ())
383+ ret.push_back (from_node_view (e));
384+
385+ return ret;
386+ }
387+
388+
378389// Parses the same data into a tree and a
379390// flat_tree, they should be equal to each other.
380391BOOST_AUTO_TEST_CASE (flat_tree_views_are_set)
381392{
382393 tree resp1;
383- flat_tree fresp;
394+ flat_tree resp2;
395+ generic_flat_response resp3;
384396
385397 error_code ec;
386398 deserialize (resp3_set, adapt2 (resp1), ec);
387399 BOOST_CHECK_EQUAL (ec, error_code{});
388400
389- deserialize (resp3_set, adapt2 (fresp ), ec);
401+ deserialize (resp3_set, adapt2 (resp2 ), ec);
390402 BOOST_CHECK_EQUAL (ec, error_code{});
391403
392- BOOST_CHECK_EQUAL (fresp.get_reallocs (), 1u );
393- BOOST_CHECK_EQUAL (fresp.get_total_msgs (), 1u );
404+ deserialize (resp3_set, adapt2 (resp3), ec);
405+ BOOST_CHECK_EQUAL (ec, error_code{});
406+
407+ BOOST_CHECK_EQUAL (resp2.get_reallocs (), 1u );
408+ BOOST_CHECK_EQUAL (resp2.get_total_msgs (), 1u );
409+
410+ BOOST_CHECK_EQUAL (resp3.value ().get_reallocs (), 1u );
411+ BOOST_CHECK_EQUAL (resp3.value ().get_total_msgs (), 1u );
412+
413+ auto const tmp2 = from_flat (resp2);
414+ BOOST_CHECK_EQUAL (resp1, tmp2);
394415
395- auto const resp2 = from_flat (fresp );
396- BOOST_CHECK_EQUAL (resp1, resp2 );
416+ auto const tmp3 = from_flat (resp3 );
417+ BOOST_CHECK_EQUAL (resp1, tmp3 );
397418}
398419
399420// The response should be reusable.
@@ -446,3 +467,39 @@ BOOST_AUTO_TEST_CASE(flat_tree_copy_assign)
446467 BOOST_TEST ((copy2 == resp));
447468 BOOST_TEST ((copy3 == resp));
448469}
470+
471+ BOOST_AUTO_TEST_CASE (generic_flat_response_simple_error)
472+ {
473+ generic_flat_response resp;
474+
475+ char const * wire = " -Error\r\n " ;
476+
477+ error_code ec;
478+ deserialize (wire, adapt2 (resp), ec);
479+ BOOST_CHECK_EQUAL (ec, error_code{});
480+
481+ BOOST_TEST (!resp.has_value ());
482+ BOOST_TEST (resp.has_error ());
483+ auto const error = resp.error ();
484+
485+ BOOST_CHECK_EQUAL (error.data_type , boost::redis::resp3::type::simple_error);
486+ BOOST_CHECK_EQUAL (error.diagnostic , std::string{" Error" });
487+ }
488+
489+ BOOST_AUTO_TEST_CASE (generic_flat_response_blob_error)
490+ {
491+ generic_flat_response resp;
492+
493+ char const * wire = " !5\r\n Error\r\n " ;
494+
495+ error_code ec;
496+ deserialize (wire, adapt2 (resp), ec);
497+ BOOST_CHECK_EQUAL (ec, error_code{});
498+
499+ BOOST_TEST (!resp.has_value ());
500+ BOOST_TEST (resp.has_error ());
501+ auto const error = resp.error ();
502+
503+ BOOST_CHECK_EQUAL (error.data_type , boost::redis::resp3::type::blob_error);
504+ BOOST_CHECK_EQUAL (error.diagnostic , std::string{" Error" });
505+ }
0 commit comments