2019-06-22 16:58:45 +09:00
|
|
|
#define BOOST_TEST_MODULE "test_expect"
|
2017-12-11 14:30:25 +09:00
|
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#else
|
|
|
|
#define BOOST_TEST_NO_LIB
|
2017-12-11 12:04:57 +09:00
|
|
|
#include <boost/test/included/unit_test.hpp>
|
2017-12-11 14:30:25 +09:00
|
|
|
#endif
|
2017-12-11 12:04:57 +09:00
|
|
|
#include <toml.hpp>
|
|
|
|
#include <map>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <list>
|
|
|
|
#include <deque>
|
|
|
|
#include <array>
|
|
|
|
|
2018-12-13 01:30:06 +09:00
|
|
|
BOOST_AUTO_TEST_CASE(test_expect)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
toml::value v1(42);
|
|
|
|
toml::value v2(3.14);
|
2018-12-17 23:03:53 +09:00
|
|
|
const auto v1_or_0 = toml::expect<int>(v1).unwrap_or(0);
|
|
|
|
const auto v2_or_0 = toml::expect<int>(v2).unwrap_or(0);
|
2019-06-21 15:58:22 +09:00
|
|
|
BOOST_TEST(42 == v1_or_0);
|
|
|
|
BOOST_TEST( 0 == v2_or_0);
|
2018-12-17 23:03:53 +09:00
|
|
|
|
|
|
|
const auto v1_or_none = toml::expect<int>(v1).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none"));
|
|
|
|
const auto v2_or_none = toml::expect<int>(v2).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none"));
|
2019-06-21 15:58:22 +09:00
|
|
|
BOOST_TEST("42" == v1_or_none);
|
|
|
|
BOOST_TEST("none" == v2_or_none);
|
2018-12-13 01:30:06 +09:00
|
|
|
}
|
2017-12-11 12:04:57 +09:00
|
|
|
}
|