#define BOOST_TEST_MODULE "test_expect" #ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST #include #else #define BOOST_TEST_NO_LIB #include #endif #include #include #include #include #include #include BOOST_AUTO_TEST_CASE(test_expect) { { toml::value v1(42); toml::value v2(3.14); const auto v1_or_0 = toml::expect(v1).unwrap_or(0); const auto v2_or_0 = toml::expect(v2).unwrap_or(0); BOOST_TEST(42 == v1_or_0); BOOST_TEST( 0 == v2_or_0); const auto v1_or_none = toml::expect(v1).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none")); const auto v2_or_none = toml::expect(v2).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none")); BOOST_TEST("42" == v1_or_none); BOOST_TEST("none" == v2_or_none); } }