39 lines
829 B
C++
39 lines
829 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_unknown_text")
|
|
{
|
|
m_lexer.scan(" §§§ ");
|
|
REQUIRE_THROWS_AS(m_lexer.try_next(), zn::lex_error);
|
|
}
|
|
|
|
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());
|
|
}
|