mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Add Tests for ZCG cpp
This commit is contained in:
51
test/ZoneCodeGeneratorLibTests.lua
Normal file
51
test/ZoneCodeGeneratorLibTests.lua
Normal file
@ -0,0 +1,51 @@
|
||||
ZoneCodeGeneratorLibTests = {}
|
||||
|
||||
function ZoneCodeGeneratorLibTests:include()
|
||||
if References:include(self:name()) then
|
||||
includedirs {
|
||||
path.join(TestFolder(), "ZoneCodeGeneratorLibTests")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLibTests:link()
|
||||
if References:link(self:name()) then
|
||||
links(self:name())
|
||||
end
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLibTests:use()
|
||||
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLibTests:name()
|
||||
return "ZoneCodeGeneratorLibTests"
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLibTests:project()
|
||||
References:reset()
|
||||
local folder = TestFolder();
|
||||
|
||||
project(self:name())
|
||||
targetdir(TargetDirectoryTest)
|
||||
location "%{wks.location}/test/%{prj.name}"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
path.join(folder, "ZoneCodeGeneratorLibTests/**.h"),
|
||||
path.join(folder, "ZoneCodeGeneratorLibTests/**.cpp")
|
||||
}
|
||||
|
||||
vpaths {
|
||||
["*"] = {
|
||||
path.join(folder, "ZoneCodeGeneratorLibTests"),
|
||||
}
|
||||
}
|
||||
|
||||
self:include()
|
||||
ZoneCodeGeneratorLib:include()
|
||||
catch2:include()
|
||||
|
||||
ZoneCodeGeneratorLib:link()
|
||||
end
|
@ -0,0 +1,227 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
#include "Parsing/Mock/MockParserLineStream.h"
|
||||
|
||||
namespace test::parsing
|
||||
{
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure simple single line comment is working", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"// hello",
|
||||
"prefix // test",
|
||||
"t//est"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line == "prefix ");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line == "t");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure single line comment expands to next line on backslash", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"// hello\\",
|
||||
"this should still be a comment",
|
||||
"this should not be a comment anymore"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line == "this should not be a comment anymore");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure single line comment expands to next line on backslash and is repeatable", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"// hello\\",
|
||||
"this should still be a comment \\",
|
||||
"this as well",
|
||||
"this not anymore"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 4);
|
||||
REQUIRE(line.m_line == "this not anymore");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure backslash must be last character to expand single line comment to next line", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"// hello\\",
|
||||
"this should still be a comment \\ ",
|
||||
"this not anymore"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line == "this not anymore");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure simple multiline comment works on one line", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"hello/* hell*/ world",
|
||||
"/*this should be a comment*/",
|
||||
"Hello /*asdf*/",
|
||||
"/*asdf*/World"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line == "hello world");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line == "Hello ");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 4);
|
||||
REQUIRE(line.m_line == "World");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("CommentRemovingStreamProxy: Ensure simple multiline comment works over multiple lines", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines
|
||||
{
|
||||
"hello/* hell",
|
||||
" hell*/ world/*nope",
|
||||
"notatall",
|
||||
"hehe*/xd"
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
CommentRemovingStreamProxy proxy(&mockStream);
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 1);
|
||||
REQUIRE(line.m_line == "hello");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 2);
|
||||
REQUIRE(line.m_line == " world");
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 3);
|
||||
REQUIRE(line.m_line.empty());
|
||||
}
|
||||
|
||||
{
|
||||
auto line = proxy.NextLine();
|
||||
REQUIRE(line.m_line_number == 4);
|
||||
REQUIRE(line.m_line == "xd");
|
||||
}
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#include "MockParserLineStream.h"
|
||||
|
||||
const std::string MockParserLineStream::MOCK_FILENAME;
|
||||
|
||||
MockParserLineStream::MockParserLineStream(const std::vector<std::string>& lines)
|
||||
: m_lines(lines),
|
||||
m_line(0)
|
||||
{
|
||||
}
|
||||
|
||||
ParserLine MockParserLineStream::NextLine()
|
||||
{
|
||||
if(m_line < m_lines.size())
|
||||
{
|
||||
const auto line = m_line++;
|
||||
return ParserLine(MOCK_FILENAME, line + 1, m_lines[line]);
|
||||
}
|
||||
|
||||
return ParserLine(MOCK_FILENAME, 0, std::string());
|
||||
}
|
||||
|
||||
bool MockParserLineStream::IncludeFile(const std::string& filename)
|
||||
{
|
||||
m_includes.push_back(filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MockParserLineStream::IsOpen() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MockParserLineStream::Eof() const
|
||||
{
|
||||
return m_line >= m_lines.size();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
class MockParserLineStream final : public IParserLineStream
|
||||
{
|
||||
static const std::string MOCK_FILENAME;
|
||||
|
||||
const std::vector<std::string>& m_lines;
|
||||
unsigned m_line;
|
||||
std::vector<std::string> m_includes{};
|
||||
|
||||
public:
|
||||
explicit MockParserLineStream(const std::vector<std::string>& lines);
|
||||
|
||||
ParserLine NextLine() override;
|
||||
bool IncludeFile(const std::string& filename) override;
|
||||
_NODISCARD bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
2
test/ZoneCodeGeneratorLibTests/main.cpp
Normal file
2
test/ZoneCodeGeneratorLibTests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
Reference in New Issue
Block a user