From 61a0e244daf6c3bc54768901cadb3bab5d674f57 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 20 Oct 2023 21:49:20 +0300 Subject: [PATCH] Add some more test cases exercising result initialization from {} --- test/result_default_construct.cpp | 46 +++++++++++++++++++++++++++++++ test/result_value_construct2.cpp | 12 ++++++++ 2 files changed, 58 insertions(+) diff --git a/test/result_default_construct.cpp b/test/result_default_construct.cpp index a467e36c7..ca0fcc529 100644 --- a/test/result_default_construct.cpp +++ b/test/result_default_construct.cpp @@ -28,6 +28,24 @@ int main() BOOST_TEST_EQ( r.value(), 0 ); } + { + result r{}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + + BOOST_TEST_EQ( r.value(), 0 ); + } + + { + result r = {}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + + BOOST_TEST_EQ( r.value(), 0 ); + } + { result r; @@ -35,6 +53,20 @@ int main() BOOST_TEST( !r.has_error() ); } + { + result r{}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + } + + { + result r = {}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + } + { result r; @@ -42,6 +74,20 @@ int main() BOOST_TEST( !r.has_error() ); } + { + result r{}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + } + + { + result r = {}; + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + } + { BOOST_TEST_TRAIT_TRUE((std::is_default_constructible>)); BOOST_TEST_TRAIT_TRUE((std::is_default_constructible>)); diff --git a/test/result_value_construct2.cpp b/test/result_value_construct2.cpp index 6296a4f6a..b3d92a239 100644 --- a/test/result_value_construct2.cpp +++ b/test/result_value_construct2.cpp @@ -69,6 +69,11 @@ result> fv2() return {{ 1, 2 }}; } +result fw0() +{ + return {}; +} + int main() { { @@ -148,5 +153,12 @@ int main() BOOST_TEST_EQ( r->at(1), 2 ); } + { + result r = fw0(); + + BOOST_TEST( r.has_value() ); + BOOST_TEST( !r.has_error() ); + } + return boost::report_errors(); }