From 290dca3d679a68b94e29a74973c6c1c942eb1a94 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 13 Oct 2020 22:04:28 +0900 Subject: [PATCH] test: add test for comment duplication --- tests/test_comments.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_comments.cpp b/tests/test_comments.cpp index 5ae1e0d..7438cae 100644 --- a/tests/test_comments.cpp +++ b/tests/test_comments.cpp @@ -138,6 +138,43 @@ BOOST_AUTO_TEST_CASE(test_comment_both) } } +BOOST_AUTO_TEST_CASE(test_comments_on_implicit_values) +{ + { + const std::string file = R"( + # comment for the first element of array-of-tables. + [[array-of-tables]] + foo = "bar" + )"; + std::istringstream iss(file); + const auto v = toml::parse(iss); + + const auto aot = toml::find(v, "array-of-tables"); + const auto elm = aot.at(0); + BOOST_TEST(aot.comments().empty()); + BOOST_TEST(elm.comments().size() == 1); + BOOST_TEST(elm.comments().front() == " comment for the first element of array-of-tables."); + } + { + const std::string file = R"( + # comment for the array itself + array-of-tables = [ + # comment for the first element of array-of-tables. + {foo = "bar"} + ] + )"; + std::istringstream iss(file); + const auto v = toml::parse(iss); + + const auto aot = toml::find(v, "array-of-tables"); + const auto elm = aot.at(0); + BOOST_TEST(aot.comments().size() == 1); + BOOST_TEST(aot.comments().front() == " comment for the array itself"); + BOOST_TEST(elm.comments().size() == 1); + BOOST_TEST(elm.comments().front() == " comment for the first element of array-of-tables."); + } +} + BOOST_AUTO_TEST_CASE(test_discard_comment) { const std::string file = R"(