Fix defines proxy not correctly adding first line to escape line end define

This commit is contained in:
Jan 2021-11-28 19:07:30 +01:00
parent 8bf0126e38
commit 782b05a60b
2 changed files with 23 additions and 4 deletions

View File

@ -149,7 +149,7 @@ void DefinesStreamProxy::ContinueDefine(const ParserLine& line)
const auto lineEndEscapePos = GetLineEndEscapePos(line);
if (lineEndEscapePos < 0)
{
m_current_define_value << line.m_line << " ";
m_current_define_value << line.m_line;
m_current_define.m_value = m_current_define_value.str();
m_current_define.IdentifyParameters(m_current_define_parameters);
AddDefine(std::move(m_current_define));
@ -162,7 +162,7 @@ void DefinesStreamProxy::ContinueDefine(const ParserLine& line)
else
{
if (line.m_line.size() > static_cast<unsigned>(lineEndEscapePos))
m_current_define_value << line.m_line.substr(0, static_cast<unsigned>(lineEndEscapePos)) << " ";
m_current_define_value << line.m_line.substr(0, static_cast<unsigned>(lineEndEscapePos));
}
}
@ -245,8 +245,8 @@ bool DefinesStreamProxy::MatchDefineDirective(const ParserLine& line, const unsi
m_current_define_value.str(std::string());
m_current_define_parameters = std::move(parameters);
if (currentPos < line.m_line.size() && (currentPos + 1) > static_cast<unsigned>(lineEndEscapePos))
m_current_define_value << line.m_line.substr(currentPos + 1, static_cast<unsigned>(lineEndEscapePos) - (currentPos + 1)) << " ";
if (currentPos < line.m_line.size() && (currentPos + 1) < static_cast<unsigned>(lineEndEscapePos))
m_current_define_value << line.m_line.substr(currentPos + 1, static_cast<unsigned>(lineEndEscapePos) - (currentPos + 1));
}
return true;

View File

@ -687,4 +687,23 @@ namespace test::parsing::impl::defines_stream_proxy
REQUIRE(proxy.Eof());
}
TEST_CASE("DefinesStreamProxy: Ensure defines can go over multiple lines", "[parsing][parsingstream]")
{
const std::vector<std::string> lines
{
"#define someStuff(param1) Hello param1 World \\",
"and hello universe",
"someStuff(lovely)"
};
MockParserLineStream mockStream(lines);
DefinesStreamProxy proxy(&mockStream);
ExpectLine(&proxy, 1, "");
ExpectLine(&proxy, 2, "");
ExpectLine(&proxy, 3, "Hello lovely World and hello universe");
REQUIRE(proxy.Eof());
}
}