#include "Compiler.hpp" #include "Node.hpp" #include "ParseErrorException.hpp" #include "llvm/IR/Constants.h" #include // Utility function to test boolean literal compilation void testBoolLiteral(const std::string &input, bool expectedValue) { auto compiler = std::make_unique(input, "main"); auto result = compiler->compile(); auto boolNode = std::any_cast(result); ASSERT_EQ(boolNode.getNodeType(), NODE_LITERAL); ASSERT_EQ(boolNode.getDataType(), DATATYPE_BOOL); auto value = boolNode.getValue(); ASSERT_NE(value, nullptr); auto value_constant = llvm::dyn_cast(value); ASSERT_NE(value_constant, nullptr); ASSERT_EQ(value_constant->getValue().getLimitedValue(), static_cast(expectedValue)); } // Test fixture for boolean tests class BoolTest : public ::testing::Test { protected: void SetUp() override { // Setup code if needed } void TearDown() override { // Cleanup code if needed } }; // Test cases TEST_F(BoolTest, LiteralTrue) { testBoolLiteral("true;", true); } TEST_F(BoolTest, LiteralFalse) { testBoolLiteral("false;", false); } // Negative test cases TEST_F(BoolTest, InvalidLiteral) { auto compiler = std::make_unique("notbool;", "main"); ASSERT_THROW(compiler->compile(), ParseErrorException); } TEST_F(BoolTest, MissingSemicolon) { auto compiler = std::make_unique("true", "main"); ASSERT_THROW(compiler->compile(), ParseCollectiveErrorException); } TEST_F(BoolTest, MixedCaseLiteral) { auto compiler = std::make_unique("True;", "main"); ASSERT_THROW(compiler->compile(), ParseErrorException); }