2020-06-26 18:01:27 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-06-26 18:01:27 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "tests.h"
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
TEST_CASE("parsing - comments")
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(# This is a full-line comment
|
2020-06-08 15:31:23 +00:00
|
|
|
key = "value" # This is a comment at the end of a line
|
|
|
|
another = "# This is not a comment"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
|
|
|
CHECK(tbl.size() == 2);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["key"] == "value"sv);
|
|
|
|
CHECK(tbl["another"] == "# This is not a comment"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(# this = "looks like a KVP but is commented out)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-04-02 21:39:21 +00:00
|
|
|
{
|
|
|
|
CHECK(tbl.size() == 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-04-08 13:33:57 +00:00
|
|
|
#if TOML_LANG_AT_LEAST(1, 0, 0)
|
2020-04-02 21:39:21 +00:00
|
|
|
{
|
|
|
|
// toml/issues/567 (disallow non-TAB control characters in comments)
|
|
|
|
// 00 - 08
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0000 some trailing garbage"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0001"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0002"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0003"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0004"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0005"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0006"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0007"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0008"sv);
|
2020-04-02 21:39:21 +00:00
|
|
|
|
|
|
|
// 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
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u000E"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u000F"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0010"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0011"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0012"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0013"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0014"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0015"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0016"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0017"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0018"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u0019"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001A"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001B"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001C"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001D"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001E"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u001F"sv);
|
2020-04-02 21:39:21 +00:00
|
|
|
// 7F
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "# \u007F"sv);
|
2020-04-02 21:39:21 +00:00
|
|
|
}
|
2020-04-08 13:33:57 +00:00
|
|
|
#else
|
2020-04-02 21:39:21 +00:00
|
|
|
{
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, S(
|
2020-04-02 21:39:21 +00:00
|
|
|
"## 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
|
|
|
|
));
|
|
|
|
}
|
2020-04-08 13:33:57 +00:00
|
|
|
#endif
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|