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};
|
2023-08-31 19:25:00 +00:00
|
|
|
roza::SymTable sym;
|
2023-08-30 18:06:26 +00:00
|
|
|
roza::TypeResolver resolver {log};
|
|
|
|
|
|
|
|
lexer.scan(source);
|
|
|
|
auto node = parser.parse();
|
2023-08-31 19:25:00 +00:00
|
|
|
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));
|
|
|
|
}
|