This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues/pull-requests.
zarn/tests/Parser.cpp

38 lines
817 B
C++
Raw Normal View History

#include <catch2/catch.hpp>
#include "../src/Parser.hpp"
#include "../src/Lexer.hpp"
class ParserTest
{
public:
explicit ParserTest() {}
virtual ~ParserTest() {}
void test_parse(std::string const& oracle,
std::string const& source)
{
zn::Logger logger;
zn::Loc loc {"tests/parser"};
zn::Lexer lexer { logger, loc };
lexer.scan(source);
std::vector<std::shared_ptr<zn::Node>> tokens = lexer.all();
zn::Parser parser {logger};
auto node = parser.parse(tokens);
REQUIRE(oracle == node->string());
}
protected:
};
TEST_CASE_METHOD(ParserTest, "Parser_int")
{
test_parse("MODULE(INT[37])", " 37");
}
TEST_CASE_METHOD(ParserTest, "Parser_call")
{
test_parse("MODULE(CALL(IDENT[hello],INT[1],INT[2],IDENT[world]))",
" (hello 1 2 world)");
}