Fix comment removing defines proxy not properly removing multiple comments per line

This commit is contained in:
Jan 2021-11-28 19:29:50 +01:00
parent 782b05a60b
commit 8e7cd0140c
2 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,7 @@ ParserLine CommentRemovingStreamProxy::NextLine()
if (c == '*' && i + 1 < line.m_line.size() && line.m_line[i + 1] == '/') if (c == '*' && i + 1 < line.m_line.size() && line.m_line[i + 1] == '/')
{ {
line.m_line.erase(multiLineCommentStart, i + 2 - multiLineCommentStart); line.m_line.erase(multiLineCommentStart, i + 2 - multiLineCommentStart);
i = multiLineCommentStart - 1;
multiLineCommentStart = 0; multiLineCommentStart = 0;
m_inside_multi_line_comment = false; m_inside_multi_line_comment = false;
} }

View File

@ -223,4 +223,30 @@ namespace test::parsing::impl::comment_removing_stream_proxy
REQUIRE(proxy.Eof()); REQUIRE(proxy.Eof());
} }
TEST_CASE("CommentRemovingStreamProxy: Can have multiple comment blocks in one line", "[parsing][parsingstream]")
{
const std::vector<std::string> lines
{
"Hello/* lovely*/ world and/* beautiful*/ universe",
"Hello/* lovely*/ world// and beautiful universe",
};
MockParserLineStream mockStream(lines);
CommentRemovingStreamProxy proxy(&mockStream);
{
auto line = proxy.NextLine();
REQUIRE(line.m_line_number == 1);
REQUIRE(line.m_line == "Hello world and universe");
}
{
auto line = proxy.NextLine();
REQUIRE(line.m_line_number == 2);
REQUIRE(line.m_line == "Hello world");
}
REQUIRE(proxy.Eof());
}
} }