mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-16 16:28:09 +08:00
test: update tests for comment
This commit is contained in:
@@ -21,7 +21,7 @@ set(TEST_NAMES
|
||||
test_parse_key
|
||||
test_parse_table_key
|
||||
test_literals
|
||||
# test_comments
|
||||
test_comments
|
||||
test_get
|
||||
test_get_related_func
|
||||
test_parse_file
|
||||
|
@@ -10,45 +10,46 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_comment_before)
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
{
|
||||
const toml::value v = u8R"(
|
||||
const std::string file = u8R"(
|
||||
# comment for a.
|
||||
a = 42
|
||||
# comment for b.
|
||||
b = "baz"
|
||||
)"_toml;
|
||||
)";
|
||||
std::istringstream iss(file);
|
||||
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), u8"# comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), u8"# comment for b.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), "");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), "");
|
||||
const auto& a = toml::find(v, "a");
|
||||
const auto& b = toml::find(v, "b");
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8"# comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
||||
BOOST_CHECK_EQUAL(a.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||
BOOST_CHECK_EQUAL(b.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(b.comments().front(), u8" comment for b.");
|
||||
}
|
||||
|
||||
{
|
||||
const toml::value v = u8R"(
|
||||
const std::string file = u8R"(
|
||||
# comment for a.
|
||||
# another comment for a.
|
||||
a = 42
|
||||
# comment for b.
|
||||
# also comment for b.
|
||||
b = "baz"
|
||||
)"_toml;
|
||||
)";
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), u8R"(# comment for a.
|
||||
# another comment for a.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), u8R"(# comment for b.
|
||||
# also comment for b.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), u8"");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), u8"");
|
||||
std::istringstream iss(file);
|
||||
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
||||
# another comment for a.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8R"(# comment for b.
|
||||
# also comment for b.)");
|
||||
const auto& a = toml::find(v, "a");
|
||||
const auto& b = toml::find(v, "b");
|
||||
|
||||
BOOST_CHECK_EQUAL(a.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||
BOOST_CHECK_EQUAL(a.comments().back(), u8" another comment for a.");
|
||||
BOOST_CHECK_EQUAL(b.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(b.comments().front(), u8" comment for b.");
|
||||
BOOST_CHECK_EQUAL(b.comments().back(), u8" also comment for b.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,48 +57,46 @@ BOOST_AUTO_TEST_CASE(test_comment_inline)
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
{
|
||||
const toml::value v = u8R"(
|
||||
const std::string file = u8R"(
|
||||
a = 42 # comment for a.
|
||||
b = "baz" # comment for b.
|
||||
)"_toml;
|
||||
)";
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), "");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), u8"# comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), u8"# comment for b.");
|
||||
std::istringstream iss(file);
|
||||
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8"# comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
||||
const auto& a = toml::find(v, "a");
|
||||
const auto& b = toml::find(v, "b");
|
||||
|
||||
BOOST_CHECK_EQUAL(a.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||
BOOST_CHECK_EQUAL(b.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(b.comments().front(), u8" comment for b.");
|
||||
}
|
||||
{
|
||||
const toml::value v = u8R"(
|
||||
a = [ # comment for a.
|
||||
const std::string file = u8R"(
|
||||
a = [
|
||||
42,
|
||||
] # this also.
|
||||
b = [ # comment for b.
|
||||
"bar",
|
||||
]
|
||||
c = [
|
||||
3.14, # this is not a comment for c, but 3.14.
|
||||
] # comment for c.
|
||||
)"_toml;
|
||||
] # comment for a.
|
||||
b = [
|
||||
"bar", # this is not a comment for b, but "bar"
|
||||
] # this is a comment for b.
|
||||
)";
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), "");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment_before(), "");
|
||||
std::istringstream iss(file);
|
||||
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), u8R"(# comment for a.
|
||||
# this also.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), u8"# comment for b.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment_inline(), u8"# comment for c.");
|
||||
const auto& a = toml::find(v, "a");
|
||||
const auto& b = toml::find(v, "b");
|
||||
const auto& b0 = b.as_array().at(0);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
||||
# this also.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment(), u8"# comment for c.");
|
||||
|
||||
const auto& c0 = toml::find<toml::array>(v, "c").at(0);
|
||||
BOOST_CHECK_EQUAL(c0.comment(), u8"# this is not a comment for c, but 3.14.");
|
||||
BOOST_CHECK_EQUAL(a.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||
BOOST_CHECK_EQUAL(b.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(b.comments().front(), u8" this is a comment for b.");
|
||||
BOOST_CHECK_EQUAL(b0.comments().size(), 1u);
|
||||
BOOST_CHECK_EQUAL(b0.comments().front(),
|
||||
u8" this is not a comment for b, but \"bar\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,21 +104,39 @@ BOOST_AUTO_TEST_CASE(test_comment_both)
|
||||
{
|
||||
using namespace toml::literals::toml_literals;
|
||||
{
|
||||
const toml::value v = u8R"(
|
||||
const std::string file = u8R"(
|
||||
# comment for a.
|
||||
a = 42 # inline comment for a.
|
||||
# comment for b.
|
||||
b = "baz" # inline comment for b.
|
||||
)"_toml;
|
||||
# comment for c.
|
||||
c = [ # this comment will be ignored
|
||||
# comment for the first element.
|
||||
10 # this also.
|
||||
] # another comment for c.
|
||||
)";
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), "# comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "# comment for b.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), "# inline comment for a.");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), "# inline comment for b.");
|
||||
std::istringstream iss(file);
|
||||
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
||||
# inline comment for a.)");
|
||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8R"(# comment for b.
|
||||
# inline comment for b.)");
|
||||
const auto& a = toml::find(v, "a");
|
||||
const auto& b = toml::find(v, "b");
|
||||
const auto& c = toml::find(v, "c");
|
||||
const auto& c0 = c.as_array().at(0);
|
||||
|
||||
BOOST_CHECK_EQUAL(a.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||
BOOST_CHECK_EQUAL(a.comments().back(), u8" inline comment for a.");
|
||||
BOOST_CHECK_EQUAL(b.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(b.comments().front(), u8" comment for b.");
|
||||
BOOST_CHECK_EQUAL(b.comments().back(), u8" inline comment for b.");
|
||||
|
||||
BOOST_CHECK_EQUAL(c.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(c.comments().front(), u8" comment for c.");
|
||||
BOOST_CHECK_EQUAL(c.comments().back(), u8" another comment for c.");
|
||||
|
||||
BOOST_CHECK_EQUAL(c0.comments().size(), 2u);
|
||||
BOOST_CHECK_EQUAL(c0.comments().front(), u8" comment for the first element.");
|
||||
BOOST_CHECK_EQUAL(c0.comments().back(), u8" this also.");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user