#include "Compiler.hpp" #include "Node.hpp" #include "llvm/IR/Constants.h" #include #include "Compiler.hpp" #include "Node.hpp" #include "llvm/IR/Constants.h" #include // Utility function to test integer literal compilation void testIntegerLiteral(const std::string &input, int64_t expectedValue) { auto compiler = std::make_unique(input, "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::getSigned( llvm::Type::getInt64Ty(*compiler->getContext()), expectedValue); auto value_constant = llvm::dyn_cast(value); auto expected_value_constant = llvm::dyn_cast(expected_value); ASSERT_NE(value_constant, nullptr); // Ensure value is llvm::ConstantInt ASSERT_NE(expected_value_constant, nullptr); // Ensure expected_value is llvm::ConstantInt ASSERT_EQ(value_constant->getValue(), expected_value_constant->getValue()); // Compare values ASSERT_EQ(value, expected_value); // Pointer equality } // Test cases TEST(IntegerTest, LiteralOne) { testIntegerLiteral("1;", 1); } TEST(IntegerTest, LiteralNumberPositive) { testIntegerLiteral("67890;", 67890); } TEST(IntegerTest, LiteralNumberPositiveWithPlus) { testIntegerLiteral("+67890;", 67890); } TEST(IntegerTest, LiteralNumberNegative) { testIntegerLiteral("-67890;", -67890); }