#include "Compiler.hpp" #include "Node.hpp" #include "llvm/IR/Constants.h" #include TEST(IntegerTest, LiteralOne) { auto compiler = std::make_unique("1;", "main"); auto result = compiler->compile(); auto integer = std::any_cast(result); ASSERT_EQ(integer.getNodeType(), NODE_LITERAL); ASSERT_EQ(integer.getDataType(), DATATYPE_INTEGER); auto value = integer.getValue(); auto expected_value = llvm::ConstantInt::get(llvm::Type::getInt64Ty(*compiler->getContext()), 1, true); ASSERT_EQ(value, expected_value); } TEST(IntegerTest, LiteralNumberPositive) { auto compiler = std::make_unique("67890;", "main"); auto result = compiler->compile(); auto integer = std::any_cast(result); ASSERT_EQ(integer.getNodeType(), NODE_LITERAL); ASSERT_EQ(integer.getDataType(), DATATYPE_INTEGER); auto value = integer.getValue(); auto expected_value = llvm::ConstantInt::get(llvm::Type::getInt64Ty(*compiler->getContext()), 67890, true); ASSERT_EQ(value, expected_value); } TEST(IntegerTest, LiteralNumberPositiveWithPlus) { auto compiler = std::make_unique("+67890;", "main"); auto result = compiler->compile(); auto integer = std::any_cast(result); ASSERT_EQ(integer.getNodeType(), NODE_LITERAL); ASSERT_EQ(integer.getDataType(), DATATYPE_INTEGER); auto value = integer.getValue(); auto expected_value = llvm::ConstantInt::get(llvm::Type::getInt64Ty(*compiler->getContext()), 67890, true); ASSERT_EQ(value, expected_value); } TEST(IntegerTest, LiteralNumberNegative) { auto compiler = std::make_unique("-67890;", "main"); auto result = compiler->compile(); auto integer = std::any_cast(result); ASSERT_EQ(integer.getNodeType(), NODE_LITERAL); ASSERT_EQ(integer.getDataType(), DATATYPE_INTEGER); auto value = integer.getValue(); auto expected_value = llvm::ConstantInt::get( llvm::Type::getInt64Ty(*compiler->getContext()), -67890, true); auto value_constant = llvm::dyn_cast(value); auto expected_value_constant = llvm::dyn_cast(expected_value); ASSERT_NE(value_constant, nullptr); ASSERT_NE(expected_value_constant, nullptr); ASSERT_EQ(value_constant->getValue(), expected_value_constant->getValue()); ASSERT_EQ(value, expected_value); }