mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-08 13:50:06 +00:00
10fd14f8b9
This patch consistently changes the inclusion order for unit test files to the following: 1. The header of the unit under test (using <> includes). 2. The unit_test.hpp header (using "" includes). 3. Any additional auxiliary test headers (using "" includes and sorted alphabetically). 4. Additional system headers needed for the test (using <> includes and sorted alphabetically). 5. Conditionally included system headers (using <> includes). Putting the unit under test's header at the very beginning has the advantage of also testing that the header is self-contained. It also makes it very quick to tell what unit is tested in this file.
98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#include <toml.hpp>
|
|
|
|
#include "unit_test.hpp"
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
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);
|
|
}
|