tomlplusplus/tests/parsing_comments.cpp
Mark Gillard cb000809b0 support for upcoming TOML v1.0.0 release
see https://github.com/toml-lang/toml/issues/698 for info about TOML v1.0.0

also:
- fixed some parser error-paths not returning early enough when exceptions were disabled
- added more specific error messages for parsing errors relating to prohibited codepoints
- added compilation speed improvements (particularly for platforms lacking floating-point `std::to_chars`)
- added many minor documentation improvements
- added additional tests
2020-04-03 00:39:21 +03:00

109 lines
2.5 KiB
C++

#include "tests.h"
TEST_CASE("parsing - comments")
{
parsing_should_succeed(S(R"(
# This is a full-line comment
key = "value" # This is a comment at the end of a line
another = "# This is not a comment"
)"sv),
[](table&& tbl) noexcept
{
CHECK(tbl.size() == 2);
CHECK(tbl[S("key")] == S("value"sv));
CHECK(tbl[S("another")] == S("# This is not a comment"sv));
}
);
parsing_should_succeed(S(R"(# this = "looks like a KVP but is commented out)"sv),
[](table&& tbl) noexcept
{
CHECK(tbl.size() == 0);
}
);
if constexpr (TOML_LANG_AT_LEAST(1, 0, 0))
{
// toml/issues/567 (disallow non-TAB control characters in comments)
// 00 - 08
parsing_should_fail(S("# \u0000"sv));
parsing_should_fail(S("# \u0001"sv));
parsing_should_fail(S("# \u0002"sv));
parsing_should_fail(S("# \u0003"sv));
parsing_should_fail(S("# \u0004"sv));
parsing_should_fail(S("# \u0005"sv));
parsing_should_fail(S("# \u0006"sv));
parsing_should_fail(S("# \u0007"sv));
parsing_should_fail(S("# \u0008"sv));
// skip tab and line breaks (real and otherwise)
// \u0009 is \t
// \u000A is \n
// \u000B is \v (vertical tab)
// \u000C is \f (form feed)
// \u000D is \r
// 0E - 1F
parsing_should_fail(S("# \u000E"sv));
parsing_should_fail(S("# \u000F"sv));
parsing_should_fail(S("# \u0010"sv));
parsing_should_fail(S("# \u0011"sv));
parsing_should_fail(S("# \u0012"sv));
parsing_should_fail(S("# \u0013"sv));
parsing_should_fail(S("# \u0014"sv));
parsing_should_fail(S("# \u0015"sv));
parsing_should_fail(S("# \u0016"sv));
parsing_should_fail(S("# \u0017"sv));
parsing_should_fail(S("# \u0018"sv));
parsing_should_fail(S("# \u0019"sv));
parsing_should_fail(S("# \u001A"sv));
parsing_should_fail(S("# \u001B"sv));
parsing_should_fail(S("# \u001C"sv));
parsing_should_fail(S("# \u001D"sv));
parsing_should_fail(S("# \u001E"sv));
parsing_should_fail(S("# \u001F"sv));
// 7F
parsing_should_fail(S("# \u007F"sv));
}
else
{
parsing_should_succeed(S(
"## 00 - 08"
"# \u0000 "
"# \u0001 "
"# \u0002 "
"# \u0003 "
"# \u0004 "
"# \u0005 "
"# \u0006 "
"# \u0007 "
"# \u0008 "
"## 0A - 1F"
"# \u000A "
"# \u000B "
"# \u000C "
"# \u000D "
"# \u000E "
"# \u000F "
"# \u0010 "
"# \u0011 "
"# \u0012 "
"# \u0013 "
"# \u0014 "
"# \u0015 "
"# \u0016 "
"# \u0017 "
"# \u0018 "
"# \u0019 "
"# \u001A "
"# \u001B "
"# \u001C "
"# \u001D "
"# \u001E "
"# \u001F "
"## 7F "
"# \u007F "sv
));
}
}