mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
test: update tests for comment
This commit is contained in:
@@ -21,7 +21,7 @@ set(TEST_NAMES
|
|||||||
test_parse_key
|
test_parse_key
|
||||||
test_parse_table_key
|
test_parse_table_key
|
||||||
test_literals
|
test_literals
|
||||||
# test_comments
|
test_comments
|
||||||
test_get
|
test_get
|
||||||
test_get_related_func
|
test_get_related_func
|
||||||
test_parse_file
|
test_parse_file
|
||||||
|
|||||||
@@ -10,45 +10,46 @@
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_comment_before)
|
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.
|
# comment for a.
|
||||||
a = 42
|
a = 42
|
||||||
# comment for b.
|
# comment for b.
|
||||||
b = "baz"
|
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.");
|
const auto& a = toml::find(v, "a");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), u8"# comment for b.");
|
const auto& b = toml::find(v, "b");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), "");
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), "");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8"# comment for a.");
|
BOOST_CHECK_EQUAL(a.comments().size(), 1u);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
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.
|
# comment for a.
|
||||||
# another comment for a.
|
# another comment for a.
|
||||||
a = 42
|
a = 42
|
||||||
# comment for b.
|
# comment for b.
|
||||||
# also comment for b.
|
# also comment for b.
|
||||||
b = "baz"
|
b = "baz"
|
||||||
)"_toml;
|
)";
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), u8R"(# comment for a.
|
std::istringstream iss(file);
|
||||||
# another comment for a.)");
|
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||||
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"");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
const auto& a = toml::find(v, "a");
|
||||||
# another comment for a.)");
|
const auto& b = toml::find(v, "b");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8R"(# comment for b.
|
|
||||||
# also comment for 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;
|
using namespace toml::literals::toml_literals;
|
||||||
{
|
{
|
||||||
const toml::value v = u8R"(
|
const std::string file = u8R"(
|
||||||
a = 42 # comment for a.
|
a = 42 # comment for a.
|
||||||
b = "baz" # comment for b.
|
b = "baz" # comment for b.
|
||||||
)"_toml;
|
)";
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), "");
|
std::istringstream iss(file);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "");
|
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||||
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.");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8"# comment for a.");
|
const auto& a = toml::find(v, "a");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
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"(
|
const std::string file = u8R"(
|
||||||
a = [ # comment for a.
|
a = [
|
||||||
42,
|
42,
|
||||||
] # this also.
|
] # comment for a.
|
||||||
b = [ # comment for b.
|
b = [
|
||||||
"bar",
|
"bar", # this is not a comment for b, but "bar"
|
||||||
]
|
] # this is a comment for b.
|
||||||
c = [
|
)";
|
||||||
3.14, # this is not a comment for c, but 3.14.
|
|
||||||
] # comment for c.
|
|
||||||
)"_toml;
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_before(), "");
|
std::istringstream iss(file);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "");
|
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment_before(), "");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment_inline(), u8R"(# comment for a.
|
const auto& a = toml::find(v, "a");
|
||||||
# this also.)");
|
const auto& b = toml::find(v, "b");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_inline(), u8"# comment for b.");
|
const auto& b0 = b.as_array().at(0);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment_inline(), u8"# comment for c.");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
BOOST_CHECK_EQUAL(a.comments().size(), 1u);
|
||||||
# this also.)");
|
BOOST_CHECK_EQUAL(a.comments().front(), u8" comment for a.");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8"# comment for b.");
|
BOOST_CHECK_EQUAL(b.comments().size(), 1u);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "c").comment(), u8"# comment for c.");
|
BOOST_CHECK_EQUAL(b.comments().front(), u8" this is a comment for b.");
|
||||||
|
BOOST_CHECK_EQUAL(b0.comments().size(), 1u);
|
||||||
const auto& c0 = toml::find<toml::array>(v, "c").at(0);
|
BOOST_CHECK_EQUAL(b0.comments().front(),
|
||||||
BOOST_CHECK_EQUAL(c0.comment(), u8"# this is not a comment for c, but 3.14.");
|
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;
|
using namespace toml::literals::toml_literals;
|
||||||
{
|
{
|
||||||
const toml::value v = u8R"(
|
const std::string file = u8R"(
|
||||||
# comment for a.
|
# comment for a.
|
||||||
a = 42 # inline comment for a.
|
a = 42 # inline comment for a.
|
||||||
# comment for b.
|
# comment for b.
|
||||||
b = "baz" # inline 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.");
|
std::istringstream iss(file);
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment_before(), "# comment for b.");
|
const auto v = toml::parse<toml::preserve_comments>(iss);
|
||||||
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.");
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "a").comment(), u8R"(# comment for a.
|
const auto& a = toml::find(v, "a");
|
||||||
# inline comment for a.)");
|
const auto& b = toml::find(v, "b");
|
||||||
BOOST_CHECK_EQUAL(toml::find(v, "b").comment(), u8R"(# comment for b.
|
const auto& c = toml::find(v, "c");
|
||||||
# inline comment for b.)");
|
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