#include #include #include "../lib/Lexer.hpp" #include "lib/SrcLoc.hpp" #include "lib/StatusLog.hpp" class LexerTest { public: explicit LexerTest() {} virtual ~LexerTest() {} std::string get_str(size_t index) { auto node = m_lexer.get_or_nullptr(index); if (!node) { return ""; } else { return node->string(); } } protected: roza::StatusLog m_log; roza::Lexer m_lexer {m_log, roza::SrcLoc("lexer_tests")}; }; TEST_CASE_METHOD(LexerTest, "Lexer_integers") { m_lexer.scan("45 12 -3"); REQUIRE("INT[45]" == get_str(0)); REQUIRE("INT[12]" == get_str(1)); REQUIRE("SUB" == get_str(2)); REQUIRE("INT[3]" == get_str(3)); REQUIRE("" == get_str(4)); } TEST_CASE_METHOD(LexerTest, "Lexer_comments") { m_lexer.scan("45 # 12 \n -3"); REQUIRE("INT[45]" == get_str(0)); REQUIRE("SUB" == get_str(1)); REQUIRE("INT[3]" == get_str(2)); REQUIRE("" == get_str(3)); } TEST_CASE_METHOD(LexerTest, "Lexer_int_arith") { m_lexer.scan("+-*/%^()"); REQUIRE("ADD" == get_str(0)); REQUIRE("SUB" == get_str(1)); REQUIRE("MUL" == get_str(2)); REQUIRE("DIV" == get_str(3)); REQUIRE("MOD" == get_str(4)); REQUIRE("POW" == get_str(5)); REQUIRE("OPAR" == get_str(6)); REQUIRE("CPAR" == get_str(7)); REQUIRE("" == get_str(8)); }