mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-09 22:30:07 +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.
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include <toml/parser.hpp>
|
|
|
|
#include "unit_test.hpp"
|
|
#include "test_parse_aux.hpp"
|
|
|
|
using namespace toml;
|
|
using namespace detail;
|
|
|
|
BOOST_AUTO_TEST_CASE(test_inline_table)
|
|
{
|
|
TOML11_TEST_PARSE_EQUAL(parse_inline_table<toml::value>, "{}", table());
|
|
{
|
|
table t;
|
|
t["foo"] = toml::value(42);
|
|
t["bar"] = toml::value("baz");
|
|
TOML11_TEST_PARSE_EQUAL(parse_inline_table<toml::value>, "{foo = 42, bar = \"baz\"}", t);
|
|
}
|
|
{
|
|
table t;
|
|
table t_sub;
|
|
t_sub["name"] = toml::value("pug");
|
|
t["type"] = toml::value(t_sub);
|
|
TOML11_TEST_PARSE_EQUAL(parse_inline_table<toml::value>, "{type.name = \"pug\"}", t);
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_inline_table_value)
|
|
{
|
|
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "{}", value(table()));
|
|
{
|
|
table t;
|
|
t["foo"] = toml::value(42);
|
|
t["bar"] = toml::value("baz");
|
|
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "{foo = 42, bar = \"baz\"}", value(t));
|
|
}
|
|
{
|
|
table t;
|
|
table t_sub;
|
|
t_sub["name"] = toml::value("pug");
|
|
t["type"] = toml::value(t_sub);
|
|
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "{type.name = \"pug\"}", value(t));
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_inline_table_immutability)
|
|
{
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"a = {b = 1}\n"
|
|
"a.c = 2\n"));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
{
|
|
std::istringstream stream(std::string(
|
|
"a = {b = {c = 1}}\n"
|
|
"a.b.d = 2\n"));
|
|
BOOST_CHECK_THROW(toml::parse(stream), toml::syntax_error);
|
|
}
|
|
}
|