#include #include "../src/Lexer.hpp" using namespace sn; class LexerTest { public: explicit LexerTest() {} virtual ~LexerTest() {} void test_next(std::string const& oracle) { auto tok = m_lexer.next(); INFO("tok for '" << oracle << "' is nullopt"); REQUIRE(tok); INFO("expected '" << oracle << "', got '" << (*tok)->string() << "'"); REQUIRE(oracle == (*tok)->string()); } void test_end() { auto tok = m_lexer.next(); INFO("end not found"); REQUIRE(std::nullopt == tok); } protected: Lexer m_lexer; }; TEST_CASE_METHOD(LexerTest, "Lexer_rule") { m_lexer.scan("hello.world, -> { }"); test_next("IDENT[hello.world]"); test_next("COMMA"); test_next("RARROW"); test_next("OBRACE"); test_next("CBRACE"); test_end(); } TEST_CASE_METHOD(LexerTest, "Lexer_vars") { m_lexer.scan("$hello $WORLD = "); test_next("VAR[hello]"); test_next("VAR[WORLD]"); test_next("ASSIGN"); test_end(); }