#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("INT[-3]" == get_str(2)); REQUIRE("" == get_str(3)); } TEST_CASE_METHOD(LexerTest, "Lexer_comments") { m_lexer.scan("45 # 12 \n -3"); REQUIRE("INT[45]" == get_str(0)); REQUIRE("INT[-3]" == get_str(1)); REQUIRE("" == get_str(2)); }