This repository has been archived on 2023-09-10. You can view files and clone it, but cannot push or open issues/pull-requests.
joko/tests/Parser.cpp

37 lines
808 B
C++

#include <catch2/catch.hpp>
#include "../lib/Parser.hpp"
#include "../lib/Factory.hpp"
class ParserTest
{
public:
explicit ParserTest() {}
virtual ~ParserTest() {}
void test_parser(std::string const& oracle, std::string const& source)
{
auto parser = jk::Factory(m_logger, "tests/parser").make_parser();
auto root = parser->parse(source);
REQUIRE(oracle == root->string());
}
protected:
jk::Logger m_logger;
};
TEST_CASE_METHOD(ParserTest, "Parser_funcall")
{
test_parser("PROG",
" ");
test_parser("PROG(FUNCALL(IDENT[hello]))",
" (hello) ");
test_parser("PROG(FUNCALL(IDENT[hello],INT[1],INT[2]))",
" (hello 1 2) ");
test_parser("PROG(FUNCALL(IDENT[hello],INT[1],INT[2],IDENT[bim!]))",
" (hello 1 2 bim!) ");
}