This repository has been archived on 2024-04-23. You can view files and clone it, but cannot push or open issues/pull-requests.
sine-patre-old/tests/Lexer.cpp

71 lines
1.2 KiB
C++
Raw Permalink Normal View History

2023-10-10 13:29:22 +00:00
#include <catch2/catch.hpp>
#include "../src/fol/Lexer.hpp"
using namespace sp::fol;
class LexerTest
{
public:
explicit LexerTest() {}
virtual ~LexerTest() {}
void test_next(Lexer& lexer, std::string const& oracle)
{
auto token = lexer.next();
REQUIRE(nullptr != token);
REQUIRE(oracle == token->string());
}
void test_end(Lexer& lexer)
{
auto token = lexer.next();
REQUIRE(nullptr == token);
}
protected:
};
TEST_CASE_METHOD(LexerTest, "Lexer_var")
{
Lexer lexer;
lexer.scan("hello");
test_next(lexer, "VAR[hello]");
test_end(lexer);
}
TEST_CASE_METHOD(LexerTest, "Lexer_operators")
{
Lexer lexer;
lexer.scan("&!salut|(monde)->hello");
test_next(lexer, "AND");
test_next(lexer, "NOT");
test_next(lexer, "VAR[salut]");
test_next(lexer, "OR");
test_next(lexer, "OPAR");
test_next(lexer, "VAR[monde]");
test_next(lexer, "CPAR");
test_next(lexer, "IMP");
test_next(lexer, "VAR[hello]");
test_end(lexer);
}
TEST_CASE_METHOD(LexerTest, "Lexer_pred")
{
Lexer lexer;
lexer.scan("Hello");
test_next(lexer, "PRED[Hello]");
test_end(lexer);
}
TEST_CASE_METHOD(LexerTest, "Lexer_const")
{
Lexer lexer;
lexer.scan("HELLO");
test_next(lexer, "CONST[HELLO]");
test_end(lexer);
}