roza/tests/TypeResolver.cpp

45 lines
999 B
C++
Raw Permalink Normal View History

2023-08-30 18:06:26 +00:00
#include <catch2/catch.hpp>
#include "../lib/TypeResolver.hpp"
#include "../lib/Lexer.hpp"
#include "../lib/Parser.hpp"
#include "lib/Type.hpp"
class TypeResolverTest
{
public:
explicit TypeResolverTest() {}
virtual ~TypeResolverTest() {}
std::shared_ptr<roza::Type> get_ty(std::string const& source)
{
roza::SrcLoc loc {"compiler_tests"};
roza::StatusLog log;
roza::Lexer lexer {log, loc};
roza::Parser parser {lexer, log};
roza::SymTable sym;
2023-08-30 18:06:26 +00:00
roza::TypeResolver resolver {log};
lexer.scan(source);
auto node = parser.parse();
return resolver.find(node, sym);
2023-08-30 18:06:26 +00:00
}
void test_ty(std::string const& source, std::shared_ptr<roza::Type> ty)
{
REQUIRE(ty);
test_ty(source, *ty);
}
void test_ty(std::string const& source, roza::Type const& ty)
{
REQUIRE(get_ty(source)->equals(ty));
}
protected:
};
TEST_CASE_METHOD(TypeResolverTest, "TypeResolver_")
{
test_ty(" 42 ", std::make_shared<roza::Type>(roza::BaseType::TY_INT));
}