2018-12-22 08:43:42 +00:00
|
|
|
#define BOOST_TEST_MODULE "test_error_detection"
|
|
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#else
|
|
|
|
#define BOOST_TEST_NO_LIB
|
|
|
|
#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\""));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_missing_value)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string("a ="));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_too_many_value)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string("a = 1 = \"value\""));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_duplicate_table)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"[table]\n"
|
|
|
|
"a = 42\n"
|
|
|
|
"[table]\n"
|
|
|
|
"b = 42\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflict_array_table)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"[[table]]\n"
|
|
|
|
"a = 42\n"
|
|
|
|
"[table]\n"
|
|
|
|
"b = 42\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflict_table_array)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"[table]\n"
|
|
|
|
"a = 42\n"
|
|
|
|
"[[table]]\n"
|
|
|
|
"b = 42\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_duplicate_value)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"a = 1\n"
|
|
|
|
"a = 2\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_conflicting_value)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"a.b = 1\n"
|
|
|
|
"a.b.c = 2\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_inhomogeneous_array)
|
|
|
|
{
|
2020-04-03 14:42:58 +00:00
|
|
|
#ifdef TOML11_DISALLOW_HETEROGENEOUS_ARRAYS
|
2018-12-22 08:43:42 +00:00
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"a = [1, 1.0]\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2020-04-03 14:42:58 +00:00
|
|
|
#else
|
|
|
|
BOOST_TEST_MESSAGE("After v1.0.0-rc.1, heterogeneous arrays are allowed");
|
2019-11-08 06:39:14 +00:00
|
|
|
#endif
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_detect_appending_array_of_table)
|
|
|
|
{
|
|
|
|
std::istringstream stream(std::string(
|
|
|
|
"a = [{b = 1}]\n"
|
|
|
|
"[[a]]\n"
|
|
|
|
"b = 2\n"
|
|
|
|
));
|
2019-06-21 05:47:27 +00:00
|
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
2018-12-22 08:43:42 +00:00
|
|
|
}
|