mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
test: add comment/no-comment cases to parse_array
When we add a macro to change the default comment preservation scheme, some of the current tests that assume comments are discarded by defualt fails. To make it more robust, we need to explicitly specify the comment preservation scheme and add test cases for both of discard_ and preserve_comments.
This commit is contained in:
@@ -71,62 +71,153 @@ BOOST_AUTO_TEST_CASE(test_oneline_array_value)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_multiline_array)
|
||||
{
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<toml::value>, "[\n#comment\n]", array());
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value< discard_comments>>, "[\n#comment\n]", typename basic_value< discard_comments>::array_type());
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<preserve_comments>>, "[\n#comment\n]", typename basic_value<preserve_comments>::array_type());
|
||||
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4);
|
||||
a[3] = toml::value(1); a[4] = toml::value(5);
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<toml::value>, "[3,\n1,\n4,\n1,\n5]", a);
|
||||
typename basic_value<discard_comments>::array_type a(5);
|
||||
a[0] = basic_value<discard_comments>(3);
|
||||
a[1] = basic_value<discard_comments>(1);
|
||||
a[2] = basic_value<discard_comments>(4);
|
||||
a[3] = basic_value<discard_comments>(1);
|
||||
a[4] = basic_value<discard_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<discard_comments>>, "[3,\n1,\n4,\n1,\n5]", a);
|
||||
}
|
||||
{
|
||||
array a(3);
|
||||
a[0] = toml::value("foo"); a[1] = toml::value("bar");
|
||||
a[2] = toml::value("baz");
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<toml::value>, "[\"foo\",\n\"bar\",\n\"baz\"]", a);
|
||||
typename basic_value<preserve_comments>::array_type a(5);
|
||||
a[0] = basic_value<preserve_comments>(3);
|
||||
a[1] = basic_value<preserve_comments>(1);
|
||||
a[2] = basic_value<preserve_comments>(4);
|
||||
a[3] = basic_value<preserve_comments>(1);
|
||||
a[4] = basic_value<preserve_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<preserve_comments>>, "[3,\n1,\n4,\n1,\n5]", a);
|
||||
}
|
||||
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4);
|
||||
a[3] = toml::value(1); a[4] = toml::value(5);
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<toml::value>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5]", a);
|
||||
typename basic_value<discard_comments>::array_type a(5);
|
||||
a[0] = basic_value<discard_comments>(3);
|
||||
a[1] = basic_value<discard_comments>(1);
|
||||
a[2] = basic_value<discard_comments>(4);
|
||||
a[3] = basic_value<discard_comments>(1);
|
||||
a[4] = basic_value<discard_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<discard_comments>>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", a);
|
||||
}
|
||||
{
|
||||
array a(3);
|
||||
a[0] = toml::value("foo"); a[1] = toml::value("b#r");
|
||||
a[2] = toml::value("b#z");
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<toml::value>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", a);
|
||||
typename basic_value<preserve_comments>::array_type a(5);
|
||||
a[0] = basic_value<preserve_comments>(3, {"comment"});
|
||||
a[1] = basic_value<preserve_comments>(1, {"comment"});
|
||||
a[2] = basic_value<preserve_comments>(4, {"comment"});
|
||||
a[3] = basic_value<preserve_comments>(1, {"comment"});
|
||||
a[4] = basic_value<preserve_comments>(5, {"comment"});
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<preserve_comments>>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", a);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
typename basic_value<discard_comments>::array_type a(3);
|
||||
a[0] = basic_value<discard_comments>("foo");
|
||||
a[1] = basic_value<discard_comments>("bar");
|
||||
a[2] = basic_value<discard_comments>("baz");
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<discard_comments>>, "[\"foo\",\n\"bar\",\n\"baz\"]", a);
|
||||
}
|
||||
{
|
||||
typename basic_value<preserve_comments>::array_type a(3);
|
||||
a[0] = basic_value<preserve_comments>("foo");
|
||||
a[1] = basic_value<preserve_comments>("bar");
|
||||
a[2] = basic_value<preserve_comments>("baz");
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<preserve_comments>>, "[\"foo\",\n\"bar\",\n\"baz\"]", a);
|
||||
}
|
||||
|
||||
{
|
||||
typename basic_value<discard_comments>::array_type a(3);
|
||||
a[0] = basic_value<discard_comments>("foo");
|
||||
a[1] = basic_value<discard_comments>("b#r");
|
||||
a[2] = basic_value<discard_comments>("b#z");
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<discard_comments>>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", a);
|
||||
}
|
||||
{
|
||||
typename basic_value<preserve_comments>::array_type a(3);
|
||||
a[0] = basic_value<preserve_comments>("foo", {"comment"});
|
||||
a[1] = basic_value<preserve_comments>("b#r", {"comment"});
|
||||
a[2] = basic_value<preserve_comments>("b#z", {"comment"});
|
||||
TOML11_TEST_PARSE_EQUAL(parse_array<basic_value<preserve_comments>>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", a);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_multiline_array_value)
|
||||
{
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\n#comment\n]", toml::value(array()));
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value< discard_comments>>, "[\n#comment\n]", basic_value< discard_comments>(typename basic_value< discard_comments>::array_type()));
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>, "[\n#comment\n]", basic_value<preserve_comments>(typename basic_value<preserve_comments>::array_type()));
|
||||
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4);
|
||||
a[3] = toml::value(1); a[4] = toml::value(5);
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[3,\n1,\n4,\n1,\n5]", toml::value(a));
|
||||
typename basic_value<discard_comments>::array_type a(5);
|
||||
a[0] = basic_value<discard_comments>(3);
|
||||
a[1] = basic_value<discard_comments>(1);
|
||||
a[2] = basic_value<discard_comments>(4);
|
||||
a[3] = basic_value<discard_comments>(1);
|
||||
a[4] = basic_value<discard_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<discard_comments>>, "[3,\n1,\n4,\n1,\n5]", basic_value<discard_comments>(a));
|
||||
}
|
||||
{
|
||||
array a(3);
|
||||
a[0] = toml::value("foo"); a[1] = toml::value("bar");
|
||||
a[2] = toml::value("baz");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",\n\"bar\",\n\"baz\"]", toml::value(a));
|
||||
typename basic_value<preserve_comments>::array_type a(5);
|
||||
a[0] = basic_value<preserve_comments>(3);
|
||||
a[1] = basic_value<preserve_comments>(1);
|
||||
a[2] = basic_value<preserve_comments>(4);
|
||||
a[3] = basic_value<preserve_comments>(1);
|
||||
a[4] = basic_value<preserve_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>, "[3,\n1,\n4,\n1,\n5]", basic_value<preserve_comments>(a));
|
||||
}
|
||||
|
||||
{
|
||||
array a(5);
|
||||
a[0] = toml::value(3); a[1] = toml::value(1); a[2] = toml::value(4);
|
||||
a[3] = toml::value(1); a[4] = toml::value(5);
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5]", toml::value(a));
|
||||
typename basic_value<discard_comments>::array_type a(5);
|
||||
a[0] = basic_value<discard_comments>(3);
|
||||
a[1] = basic_value<discard_comments>(1);
|
||||
a[2] = basic_value<discard_comments>(4);
|
||||
a[3] = basic_value<discard_comments>(1);
|
||||
a[4] = basic_value<discard_comments>(5);
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<discard_comments>>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", basic_value<discard_comments>(a));
|
||||
}
|
||||
{
|
||||
array a(3);
|
||||
a[0] = toml::value("foo"); a[1] = toml::value("b#r");
|
||||
a[2] = toml::value("b#z");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", toml::value(a));
|
||||
typename basic_value<preserve_comments>::array_type a(5);
|
||||
a[0] = basic_value<preserve_comments>(3, {"comment"});
|
||||
a[1] = basic_value<preserve_comments>(1, {"comment"});
|
||||
a[2] = basic_value<preserve_comments>(4, {"comment"});
|
||||
a[3] = basic_value<preserve_comments>(1, {"comment"});
|
||||
a[4] = basic_value<preserve_comments>(5, {"comment"});
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>, "[3,#comment\n1,#comment\n4,#comment\n1,#comment\n5 #comment\n]", basic_value<preserve_comments>(a));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
typename basic_value<discard_comments>::array_type a(3);
|
||||
a[0] = basic_value<discard_comments>("foo");
|
||||
a[1] = basic_value<discard_comments>("bar");
|
||||
a[2] = basic_value<discard_comments>("baz");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<discard_comments>>, "[\"foo\",\n\"bar\",\n\"baz\"]", basic_value<discard_comments>(a));
|
||||
}
|
||||
{
|
||||
typename basic_value<preserve_comments>::array_type a(3);
|
||||
a[0] = basic_value<preserve_comments>("foo");
|
||||
a[1] = basic_value<preserve_comments>("bar");
|
||||
a[2] = basic_value<preserve_comments>("baz");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>, "[\"foo\",\n\"bar\",\n\"baz\"]", basic_value<preserve_comments>(a));
|
||||
}
|
||||
|
||||
{
|
||||
typename basic_value<discard_comments>::array_type a(3);
|
||||
a[0] = basic_value<discard_comments>("foo");
|
||||
a[1] = basic_value<discard_comments>("b#r");
|
||||
a[2] = basic_value<discard_comments>("b#z");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<discard_comments>>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", basic_value<discard_comments>(a));
|
||||
}
|
||||
{
|
||||
typename basic_value<preserve_comments>::array_type a(3);
|
||||
a[0] = basic_value<preserve_comments>("foo", {"comment"});
|
||||
a[1] = basic_value<preserve_comments>("b#r", {"comment"});
|
||||
a[2] = basic_value<preserve_comments>("b#z", {"comment"});
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>, "[\"foo\",#comment\n\"b#r\",#comment\n\"b#z\"#comment\n]", basic_value<preserve_comments>(a));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_heterogeneous_array)
|
||||
@@ -176,14 +267,27 @@ BOOST_AUTO_TEST_CASE(test_heterogeneous_array)
|
||||
BOOST_AUTO_TEST_CASE(test_comments_after_comma)
|
||||
{
|
||||
{
|
||||
array a;
|
||||
a.push_back("foo");
|
||||
a.push_back("bar");
|
||||
a.push_back("baz");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>,
|
||||
typename basic_value<discard_comments>::array_type a(3);
|
||||
a[0] = basic_value<discard_comments>("foo");
|
||||
a[1] = basic_value<discard_comments>("bar");
|
||||
a[2] = basic_value<discard_comments>("baz");
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<discard_comments>>,
|
||||
"[ \"foo\" # comment\n"
|
||||
", \"bar\" # comment\n"
|
||||
", \"baz\" # comment\n"
|
||||
"]", toml::value(a));
|
||||
"]", basic_value<discard_comments>(a));
|
||||
}
|
||||
|
||||
{
|
||||
typename basic_value<preserve_comments>::array_type a(3);
|
||||
a[0] = basic_value<preserve_comments>("foo", {" comment"});
|
||||
a[1] = basic_value<preserve_comments>("bar", {" comment"});
|
||||
a[2] = basic_value<preserve_comments>("baz", {" comment"});
|
||||
TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<basic_value<preserve_comments>>,
|
||||
"[ \"foo\" # comment\n"
|
||||
", \"bar\" # comment\n"
|
||||
", \"baz\" # comment\n"
|
||||
"]", basic_value<preserve_comments>(a));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user