snake/tests/Parser.cpp

49 lines
1021 B
C++
Raw Normal View History

2023-10-14 01:56:31 +00:00
#include <catch2/catch.hpp>
#include "../src/Lexer.hpp"
#include "../src/Parser.hpp"
using namespace sn;
class ParserTest
{
public:
explicit ParserTest() {}
virtual ~ParserTest() {}
void test_parse(std::string const& oracle,
std::string const& source)
{
Lexer lexer;
lexer.scan(source);
Parser parser;
auto node = parser.parse(lexer.all());
REQUIRE(oracle == node->string());
}
protected:
};
TEST_CASE_METHOD(ParserTest, "Parser_rule")
{
std::stringstream ss;
ss << " hello.elf -> hello.cpp {" << std::endl;
ss << " g++ hello.cpp -o hello.elf, " << std::endl;
ss << " ls " << std::endl;
ss << " }" << std::endl;
test_parse("DOC(RULE(TARGET("
"IDENT[hello.elf]"
"),DEPS("
"IDENT[hello.cpp]"
"),BLOCK("
"CMD("
"IDENT[g++],IDENT[hello.cpp],IDENT[-o],IDENT[hello.elf]"
"),CMD("
"IDENT[ls]"
")"
")))",
ss.str());
}