2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-31 08:12:26 +00:00
This commit is contained in:
Emil Dotchevski
2020-10-20 12:23:13 -07:00
parent c20262d1f8
commit 44eec77cf0
103 changed files with 15900 additions and 15900 deletions

View File

@@ -13,65 +13,65 @@ namespace leaf = boost::leaf;
template <int>
struct info
{
int value;
int value;
};
template <class G>
leaf::error_id f( G && g )
{
return std::forward<G>(g)();
return std::forward<G>(g)();
}
template <class G>
void test( G && g )
{
int r = leaf::try_handle_all(
[&]() -> leaf::result<int>
{
return f(std::move(g));
},
[]( info<42> const & i42, leaf::diagnostic_info const & di )
{
BOOST_TEST_EQ(i42.value, 42);
std::stringstream ss; ss << di;
std::string s = ss.str();
std::cout << s;
int r = leaf::try_handle_all(
[&]() -> leaf::result<int>
{
return f(std::move(g));
},
[]( info<42> const & i42, leaf::diagnostic_info const & di )
{
BOOST_TEST_EQ(i42.value, 42);
std::stringstream ss; ss << di;
std::string s = ss.str();
std::cout << s;
#if BOOST_LEAF_DIAGNOSTICS
BOOST_TEST(s.find("info<-42>")!=s.npos);
BOOST_TEST(s.find("info<-42>")!=s.npos);
#else
BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos);
BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos);
#endif
return 1;
},
[]
{
return 2;
} );
BOOST_TEST_EQ(r, 1);
return 1;
},
[]
{
return 2;
} );
BOOST_TEST_EQ(r, 1);
}
int main()
{
test(
[]
{
auto load = leaf::on_error( info<42>{42}, info<-42>{-42} );
return leaf::new_error();
});
test(
[]
{
info<42> inf1{42};
info<-42> const inf2{-42};
auto load = leaf::on_error( inf1, inf2 );
return leaf::new_error();
});
test(
[]
{
info<42> inf1{42};
auto load = leaf::on_error( inf1, info<-42>{-42} );
return leaf::new_error();
});
return boost::report_errors();
test(
[]
{
auto load = leaf::on_error( info<42>{42}, info<-42>{-42} );
return leaf::new_error();
});
test(
[]
{
info<42> inf1{42};
info<-42> const inf2{-42};
auto load = leaf::on_error( inf1, inf2 );
return leaf::new_error();
});
test(
[]
{
info<42> inf1{42};
auto load = leaf::on_error( inf1, info<-42>{-42} );
return leaf::new_error();
});
return boost::report_errors();
}