#include #include "../lib/Lexer.hpp" class LexerTest { public: explicit LexerTest() {} virtual ~LexerTest() {} void test_next(wg::Lexer& lexer, std::string const& oracle) { auto n = lexer.next(); REQUIRE(nullptr != n); REQUIRE(oracle == n->string()); } void test_end(wg::Lexer& lexer) { auto n = lexer.next(); REQUIRE(nullptr == n); } protected: }; TEST_CASE_METHOD(LexerTest, "Lexer_") { wg::Lexer lex; lex.scan(" # canard #canard"); test_next(lex, "HASH"); test_next(lex, "IDENT[canard]"); test_next(lex, "HASH"); test_next(lex, "IDENT[canard]"); test_end(lex); } TEST_CASE_METHOD(LexerTest, "Lexer_int_literal") { wg::Lexer lex; lex.scan(" 3 -2 78 "); test_next(lex, "INT[3]"); test_next(lex, "INT[-2]"); test_next(lex, "INT[78]"); test_end(lex); } TEST_CASE_METHOD(LexerTest, "Lexer_int_arith") { wg::Lexer lex; lex.scan(" +-*/% ()"); test_next(lex, "ADD"); test_next(lex, "SUB"); test_next(lex, "MUL"); test_next(lex, "DIV"); test_next(lex, "MOD"); test_next(lex, "OPAR"); test_next(lex, "CPAR"); test_end(lex); } TEST_CASE_METHOD(LexerTest, "Lexer_fun_call") { wg::Lexer lex; lex.scan(" , int extern "); test_next(lex, "COMMA"); test_next(lex, "TYPE[int]"); test_next(lex, "EXTERN"); test_end(lex); } TEST_CASE_METHOD(LexerTest, "Lexer_pkg_namespace") { wg::Lexer lex; lex.scan(" . "); test_next(lex, "DOT"); test_end(lex); }