mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +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.
101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
#define BOOST_TEST_MODULE "test_error_detection"
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
#include <boost/test/unit_test.hpp>
|
|
#else
|
|
#include <boost/test/included/unit_test.hpp>
|
|
#endif
|
|
#include <toml.hpp>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_empty_key)
|
|
{
|
|
std::istringstream stream(std::string("= \"value\""));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_missing_value)
|
|
{
|
|
std::istringstream stream(std::string("a ="));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_too_many_value)
|
|
{
|
|
std::istringstream stream(std::string("a = 1 = \"value\""));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_duplicate_table)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"[table]\n"
|
|
"a = 42\n"
|
|
"[table]\n"
|
|
"b = 42\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflict_array_table)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"[[table]]\n"
|
|
"a = 42\n"
|
|
"[table]\n"
|
|
"b = 42\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflict_table_array)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"[table]\n"
|
|
"a = 42\n"
|
|
"[[table]]\n"
|
|
"b = 42\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_duplicate_value)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"a = 1\n"
|
|
"a = 2\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflicting_value)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"a.b = 1\n"
|
|
"a.b.c = 2\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_inhomogeneous_array)
|
|
{
|
|
#ifdef TOML11_DISALLOW_HETEROGENEOUS_ARRAYS
|
|
std::istringstream stream(std::string(
|
|
"a = [1, 1.0]\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
#else
|
|
BOOST_TEST_MESSAGE("After v1.0.0-rc.1, heterogeneous arrays are allowed");
|
|
#endif
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_appending_array_of_table)
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"a = [{b = 1}]\n"
|
|
"[[a]]\n"
|
|
"b = 2\n"
|
|
));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|