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/Lexer.cpp

44 lines
951 B
C++

#include <catch2/catch.hpp>
#include "../src/Lexer.hpp"
class LexerTest
{
public:
explicit LexerTest() {}
virtual ~LexerTest() {}
void test_next(zn::Lexer& lexer, std::string const& oracle)
{
auto node = lexer.try_next();
INFO("expected " << oracle << " got nullptr");
REQUIRE(nullptr != node);
REQUIRE(oracle == node->string());
}
protected:
zn::Logger m_logger;
zn::Loc m_loc {"tests/lexer"};
zn::Lexer m_lexer { m_logger, m_loc };
};
TEST_CASE_METHOD(LexerTest, "Lexer_int")
{
m_lexer.scan(" 3 -2 167 ");
test_next(m_lexer, "INT[3]");
test_next(m_lexer, "INT[-2]");
test_next(m_lexer, "INT[167]");
REQUIRE(nullptr == m_lexer.try_next());
}
TEST_CASE_METHOD(LexerTest, "Lexer_call")
{
m_lexer.scan(" (hello world) ");
test_next(m_lexer, "OPAR");
test_next(m_lexer, "IDENT[hello]");
test_next(m_lexer, "IDENT[world]");
test_next(m_lexer, "CPAR");
REQUIRE(nullptr == m_lexer.try_next());
}