2023-09-10 23:05:29 +00:00
|
|
|
#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)
|
|
|
|
{
|
2023-09-11 06:00:50 +00:00
|
|
|
grino::Logger logger;
|
|
|
|
grino::Lexer lexer {logger, "tests/parser"};
|
|
|
|
grino::Parser parser {logger, lexer};
|
|
|
|
|
|
|
|
auto root = parser.parse(source);
|
2023-09-10 23:05:29 +00:00
|
|
|
REQUIRE(oracle == root->string());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(ParserTest, "Parser_empty")
|
|
|
|
{
|
|
|
|
test_parse("MODULE", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(ParserTest, "Parser_booleans")
|
|
|
|
{
|
|
|
|
test_parse("MODULE(BOOL[true],BOOL[false])", "true false");
|
|
|
|
}
|
2023-09-11 06:00:50 +00:00
|
|
|
|
|
|
|
TEST_CASE_METHOD(ParserTest, "Parser_vardecl")
|
|
|
|
{
|
|
|
|
test_parse("MODULE(VARDECL(IDENT[hello],BOOL[false]))",
|
|
|
|
"($ hello false)");
|
|
|
|
|
|
|
|
test_parse("MODULE(VARDECL(IDENT[hello],IDENT[world]))",
|
|
|
|
"($ hello world)");
|
|
|
|
}
|
2023-09-11 10:14:01 +00:00
|
|
|
|
|
|
|
TEST_CASE_METHOD(ParserTest, "Parser_funcall")
|
|
|
|
{
|
|
|
|
test_parse("MODULE(FUNCALL(IDENT[hello]))",
|
|
|
|
"(hello)");
|
|
|
|
|
|
|
|
test_parse("MODULE(FUNCALL(IDENT[f],BOOL[false],BOOL[true]))",
|
|
|
|
"(f false true)");
|
|
|
|
}
|