fakir/tests/Parser.cpp

38 lines
809 B
C++
Raw Normal View History

#include <catch2/catch.hpp>
#include "../src/Parser.hpp"
class ParserTest
{
public:
explicit ParserTest() {}
virtual ~ParserTest() {}
void test_parse(std::string const& oracle, std::string const& source)
{
auto node = m_parser.parse(source);
REQUIRE(oracle == node->string());
}
protected:
fk::Loc m_loc {"tests/parser"};
fk::Lexer m_lexer { m_loc };
fk::Parser m_parser { m_lexer };
};
TEST_CASE_METHOD(ParserTest, "Parser_empty")
{
test_parse("MODULE", "");
}
TEST_CASE_METHOD(ParserTest, "Parser_builtins")
{
test_parse("MODULE(INT[4],FLOAT[3.0],BOOL[false],STRING['salut'])",
"4 3. false 'salut'");
}
2023-09-20 15:17:13 +00:00
TEST_CASE_METHOD(ParserTest, "Parser_call")
{
test_parse("MODULE(CALL(IDENT[bim],INT[2],STRING['3'],BOOL[false]))",
" (bim 2 '3' false) ");
}