mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58: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.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#define BOOST_TEST_MODULE "parse_table_test"
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
#include <boost/test/unit_test.hpp>
|
|
#else
|
|
#include <boost/test/included/unit_test.hpp>
|
|
#endif
|
|
#include <toml/parser.hpp>
|
|
#include <toml/get.hpp>
|
|
#include "test_parse_aux.hpp"
|
|
|
|
using namespace toml;
|
|
using namespace detail;
|
|
|
|
BOOST_AUTO_TEST_CASE(test_normal_table)
|
|
{
|
|
std::string table(
|
|
"key1 = \"value\"\n"
|
|
"key2 = 42\n"
|
|
"key3 = 3.14\n"
|
|
);
|
|
location loc("test", table);
|
|
|
|
const auto result = toml::detail::parse_ml_table<toml::value>(loc);
|
|
BOOST_TEST(result.is_ok());
|
|
const auto data = result.unwrap();
|
|
|
|
BOOST_TEST(toml::get<std::string >(data.at("key1")) == "value");
|
|
BOOST_TEST(toml::get<std::int64_t>(data.at("key2")) == 42);
|
|
BOOST_TEST(toml::get<double >(data.at("key3")) == 3.14);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_nested_table)
|
|
{
|
|
std::string table(
|
|
"a.b = \"value\"\n"
|
|
"a.c.d = 42\n"
|
|
);
|
|
location loc("test", table);
|
|
|
|
const auto result = toml::detail::parse_ml_table<toml::value>(loc);
|
|
BOOST_TEST(result.is_ok());
|
|
const auto data = result.unwrap();
|
|
|
|
const auto a = toml::get<toml::table>(data.at("a"));
|
|
const auto c = toml::get<toml::table>(a.at("c"));
|
|
|
|
BOOST_TEST(toml::get<std::string >(a.at("b")) == "value");
|
|
BOOST_TEST(toml::get<std::int64_t>(c.at("d")) == 42);
|
|
}
|