mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00

The conditional inclusion of either the library or the header-only version of the Boost.Test header wasn't tremendously useful in practice because the tests/CMakeLists.txt file would unconditionally add compile definitions to basically fore dynamic linking. This patch adds feature detection to the tests/CMakeLists.txt file to determine whether to use dynamic linking, static linking or the header-only version (in that order of preference, for best performance). The automatic detection could be overridden if needed by defining the TOML11_WITH_BOOST_TEST_{HEADER,STATIC,DYNAMIC} variables on the CMake command line. While we are at it, instead of having a conditional #define BOOST_TEST_NO_LIB in each unit test file, handle this once in the CMakeLists.txt file.
30 lines
934 B
C++
30 lines
934 B
C++
#define BOOST_TEST_MODULE "test_expect"
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
#include <boost/test/unit_test.hpp>
|
|
#else
|
|
#include <boost/test/included/unit_test.hpp>
|
|
#endif
|
|
#include <toml.hpp>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
#include <list>
|
|
#include <deque>
|
|
#include <array>
|
|
|
|
BOOST_AUTO_TEST_CASE(test_expect)
|
|
{
|
|
{
|
|
toml::value v1(42);
|
|
toml::value v2(3.14);
|
|
const auto v1_or_0 = toml::expect<int>(v1).unwrap_or(0);
|
|
const auto v2_or_0 = toml::expect<int>(v2).unwrap_or(0);
|
|
BOOST_TEST(42 == v1_or_0);
|
|
BOOST_TEST( 0 == v2_or_0);
|
|
|
|
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"));
|
|
BOOST_TEST("42" == v1_or_none);
|
|
BOOST_TEST("none" == v2_or_none);
|
|
}
|
|
}
|