mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:38:06 -05:00
Cache lines in Lexer and show original input when running into an error
This commit is contained in:
@ -133,4 +133,49 @@ namespace test::parsing::impl::including_stream_proxy
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("IncludingStreamProxy: Ensure pragma once prevents including the same file more than once", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"Hello world",
|
||||
"#include \"ASDF.txt\"",
|
||||
"#include \"ASDF.txt\"",
|
||||
"and bye"
|
||||
};
|
||||
|
||||
const std::vector<std::string> asdf
|
||||
{
|
||||
"#pragma once",
|
||||
"Hello galaxy"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
mockStream.AddIncludeLines("ASDF.txt", asdf);
|
||||
|
||||
IncludingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_filename.get() == MockParserLineStream::MOCK_FILENAME);
|
||||
REQUIRE(line.m_line == "Hello world");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_filename.get() == "ASDF.txt");
|
||||
REQUIRE(line.m_line == "Hello galaxy");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 4);
|
||||
REQUIRE(line.m_filename.get() == MockParserLineStream::MOCK_FILENAME);
|
||||
REQUIRE(line.m_line == "and bye");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,12 @@ bool MockParserLineStream::IncludeFile(const std::string& filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MockParserLineStream::PopCurrentFile()
|
||||
{
|
||||
if (!m_include_positions.empty())
|
||||
m_include_positions.pop_back();
|
||||
}
|
||||
|
||||
bool MockParserLineStream::IsOpen() const
|
||||
{
|
||||
return true;
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
void AddIncludeLines(const std::string& filename, const std::vector<std::string>& lines);
|
||||
ParserLine NextLine() override;
|
||||
bool IncludeFile(const std::string& filename) override;
|
||||
void PopCurrentFile() override;
|
||||
_NODISCARD bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user