/
thomas-king
/
CodeGenerator
Обзор
Документация
Войти
/
thomas-king
/
CodeGenerator
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
test/IncludeStatementTests/IncludeStatementTests.cpp
362 строки
15 KB
Ace Rodstin
Task #49. Add support for class initializer.
26 окт 2023, 16:48
26 окт 2023, 16:48
c402876
Код
Авторство
О чём код?
// // IncludeStatementTests.cpp // CodeGenerator // // Created by Ace Rodstin on 10/24/23. // Updated by Ace Rodstin on 10/26/23. // // Copyright © 2023 Ace Rodstin. All rights reserved. // #include "Support.h" TEST(IncludeStatementTests, simpleInclude) { // Given string expected = "#include \"Test.h\""; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, multipleIncludes) { // Given string expected = "#include \"First.h\"\n" "#include \"Second.h\""; // When auto includeStatement1 = Node::make<IncludeStatement>("First.h"); auto includeStatementNode1 = Node::cast<Node>(includeStatement1); auto includeStatement2 = Node::make<IncludeStatement>("Second.h"); auto includeStatementNode2 = Node::cast<Node>(includeStatement2); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode1, SourceFile::Section::HEADERS); moduleSourceFile->append(includeStatementNode2, SourceFile::Section::HEADERS); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithProperty) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value = 1;"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol { Type::Atomic::INTEGER_64, "value" }; Object constantObject { Object::Type::VALUE, constantSymbol }; Literal constantLiteral { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue { RightValue::Kind::LITERAL, constantLiteral }; auto constantDeclaration = Node::make<ConstantDeclaration>(constantObject, constantValue); auto constantDeclarationNode = Node::cast<Node>(constantDeclaration); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode, SourceFile::Section::PROPERTIES); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithProperties) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value1 = 1;\n" "const long int value2 = 2;"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol1 { Type::Atomic::INTEGER_64, "value1" }; Object constantObject1 { Object::Type::VALUE, constantSymbol1 }; Literal constantLiteral1 { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue1 { RightValue::Kind::LITERAL, constantLiteral1 }; auto constantDeclaration1 = Node::make<ConstantDeclaration>(constantObject1, constantValue1); auto constantDeclarationNode1 = Node::cast<Node>(constantDeclaration1); Symbol constantSymbol2 { Type::Atomic::INTEGER_64, "value2" }; Object constantObject2 { Object::Type::VALUE, constantSymbol2 }; Literal constantLiteral2 { Type::Atomic::INTEGER_64, 2L }; RightValue constantValue2 { RightValue::Kind::LITERAL, constantLiteral2 }; auto constantDeclaration2 = Node::make<ConstantDeclaration>(constantObject2, constantValue2); auto constantDeclarationNode2 = Node::cast<Node>(constantDeclaration2); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode1, SourceFile::Section::PROPERTIES); moduleSourceFile->append(constantDeclarationNode2, SourceFile::Section::PROPERTIES); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithPropertieWithFunction) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value1 = 1;\n" "const long int value2 = 2;\n" "\n" "void testFunction() {\n" "\n" "}"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol1 { Type::Atomic::INTEGER_64, "value1" }; Object constantObject1 { Object::Type::VALUE, constantSymbol1 }; Literal constantLiteral1 { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue1 { RightValue::Kind::LITERAL, constantLiteral1 }; auto constantDeclaration1 = Node::make<ConstantDeclaration>(constantObject1, constantValue1); auto constantDeclarationNode1 = Node::cast<Node>(constantDeclaration1); Symbol constantSymbol2 { Type::Atomic::INTEGER_64, "value2" }; Object constantObject2 { Object::Type::VALUE, constantSymbol2 }; Literal constantLiteral2 { Type::Atomic::INTEGER_64, 2L }; RightValue constantValue2 { RightValue::Kind::LITERAL, constantLiteral2 }; auto constantDeclaration2 = Node::make<ConstantDeclaration>(constantObject2, constantValue2); auto constantDeclarationNode2 = Node::cast<Node>(constantDeclaration2); Symbol functionSymbol { Type::Atomic::VOID, "testFunction" }; auto functionDeclaration = Node::make<FunctionDeclaration>(functionSymbol); auto functionDeclarationNode = Node::cast<Node>(functionDeclaration); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode1, SourceFile::Section::PROPERTIES); moduleSourceFile->append(constantDeclarationNode2, SourceFile::Section::PROPERTIES); moduleSourceFile->append(functionDeclarationNode, SourceFile::Section::FUNCTIONS); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithPropertieWithFunctions) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value1 = 1;\n" "const long int value2 = 2;\n" "\n" "void testFunction1() {\n" "\n" "}\n" "\n" "void testFunction2() {\n" "\n" "}"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol1 { Type::Atomic::INTEGER_64, "value1" }; Object constantObject1 { Object::Type::VALUE, constantSymbol1 }; Literal constantLiteral1 { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue1 { RightValue::Kind::LITERAL, constantLiteral1 }; auto constantDeclaration1 = Node::make<ConstantDeclaration>(constantObject1, constantValue1); auto constantDeclarationNode1 = Node::cast<Node>(constantDeclaration1); Symbol constantSymbol2 { Type::Atomic::INTEGER_64, "value2" }; Object constantObject2 { Object::Type::VALUE, constantSymbol2 }; Literal constantLiteral2 { Type::Atomic::INTEGER_64, 2L }; RightValue constantValue2 { RightValue::Kind::LITERAL, constantLiteral2 }; auto constantDeclaration2 = Node::make<ConstantDeclaration>(constantObject2, constantValue2); auto constantDeclarationNode2 = Node::cast<Node>(constantDeclaration2); Symbol functionSymbol1 { Type::Atomic::VOID, "testFunction1" }; auto functionDeclaration1 = Node::make<FunctionDeclaration>(functionSymbol1); auto functionDeclarationNode1 = Node::cast<Node>(functionDeclaration1); Symbol functionSymbol2 { Type::Atomic::VOID, "testFunction2" }; auto functionDeclaration2 = Node::make<FunctionDeclaration>(functionSymbol2); auto functionDeclarationNode2 = Node::cast<Node>(functionDeclaration2); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode1, SourceFile::Section::PROPERTIES); moduleSourceFile->append(constantDeclarationNode2, SourceFile::Section::PROPERTIES); moduleSourceFile->append(functionDeclarationNode1, SourceFile::Section::FUNCTIONS); moduleSourceFile->append(functionDeclarationNode2, SourceFile::Section::FUNCTIONS); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithPropertieWithFunctionsWithClass) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value1 = 1;\n" "const long int value2 = 2;\n" "\n" "void testFunction1() {\n" "\n" "}\n" "\n" "void testFunction2() {\n" "\n" "}\n" "\n" "class TestClass {\n" "\n" "};"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol1 { Type::Atomic::INTEGER_64, "value1" }; Object constantObject1 { Object::Type::VALUE, constantSymbol1 }; Literal constantLiteral1 { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue1 { RightValue::Kind::LITERAL, constantLiteral1 }; auto constantDeclaration1 = Node::make<ConstantDeclaration>(constantObject1, constantValue1); auto constantDeclarationNode1 = Node::cast<Node>(constantDeclaration1); Symbol constantSymbol2 { Type::Atomic::INTEGER_64, "value2" }; Object constantObject2 { Object::Type::VALUE, constantSymbol2 }; Literal constantLiteral2 { Type::Atomic::INTEGER_64, 2L }; RightValue constantValue2 { RightValue::Kind::LITERAL, constantLiteral2 }; auto constantDeclaration2 = Node::make<ConstantDeclaration>(constantObject2, constantValue2); auto constantDeclarationNode2 = Node::cast<Node>(constantDeclaration2); Symbol functionSymbol1 { Type::Atomic::VOID, "testFunction1" }; auto functionDeclaration1 = Node::make<FunctionDeclaration>(functionSymbol1); auto functionDeclarationNode1 = Node::cast<Node>(functionDeclaration1); Symbol functionSymbol2 { Type::Atomic::VOID, "testFunction2" }; auto functionDeclaration2 = Node::make<FunctionDeclaration>(functionSymbol2); auto functionDeclarationNode2 = Node::cast<Node>(functionDeclaration2); Symbol classSymbol { Type::Meta::CLASS, "TestClass" }; auto classDeclaration = Node::make<ClassDeclaration>(classSymbol); auto classDeclarationNode = Node::cast<Node>(classDeclaration); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode1, SourceFile::Section::PROPERTIES); moduleSourceFile->append(constantDeclarationNode2, SourceFile::Section::PROPERTIES); moduleSourceFile->append(functionDeclarationNode1, SourceFile::Section::FUNCTIONS); moduleSourceFile->append(functionDeclarationNode2, SourceFile::Section::FUNCTIONS); moduleSourceFile->append(classDeclarationNode, SourceFile::Section::CLASSES); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); } TEST(IncludeStatementTests, includeWithPropertieWithFunctionsWithClasses) { // Given string expected = "#include \"Test.h\"\n" "\n" "const long int value1 = 1;\n" "const long int value2 = 2;\n" "\n" "void testFunction1() {\n" "\n" "}\n" "\n" "void testFunction2() {\n" "\n" "}\n" "\n" "class TestClass1 {\n" "\n" "};\n" "\n" "class TestClass2 {\n" "\n" "};"; // When auto includeStatement = Node::make<IncludeStatement>("Test.h"); auto includeStatementNode = Node::cast<Node>(includeStatement); Symbol constantSymbol1 { Type::Atomic::INTEGER_64, "value1" }; Object constantObject1 { Object::Type::VALUE, constantSymbol1 }; Literal constantLiteral1 { Type::Atomic::INTEGER_64, 1L }; RightValue constantValue1 { RightValue::Kind::LITERAL, constantLiteral1 }; auto constantDeclaration1 = Node::make<ConstantDeclaration>(constantObject1, constantValue1); auto constantDeclarationNode1 = Node::cast<Node>(constantDeclaration1); Symbol constantSymbol2 { Type::Atomic::INTEGER_64, "value2" }; Object constantObject2 { Object::Type::VALUE, constantSymbol2 }; Literal constantLiteral2 { Type::Atomic::INTEGER_64, 2L }; RightValue constantValue2 { RightValue::Kind::LITERAL, constantLiteral2 }; auto constantDeclaration2 = Node::make<ConstantDeclaration>(constantObject2, constantValue2); auto constantDeclarationNode2 = Node::cast<Node>(constantDeclaration2); Symbol functionSymbol1 { Type::Atomic::VOID, "testFunction1" }; auto functionDeclaration1 = Node::make<FunctionDeclaration>(functionSymbol1); auto functionDeclarationNode1 = Node::cast<Node>(functionDeclaration1); Symbol functionSymbol2 { Type::Atomic::VOID, "testFunction2" }; auto functionDeclaration2 = Node::make<FunctionDeclaration>(functionSymbol2); auto functionDeclarationNode2 = Node::cast<Node>(functionDeclaration2); Symbol classSymbol1 { Type::Meta::CLASS, "TestClass1" }; auto classDeclaration1 = Node::make<ClassDeclaration>(classSymbol1); auto classDeclarationNode1 = Node::cast<Node>(classDeclaration1); Symbol classSymbol2 { Type::Meta::CLASS, "TestClass2" }; auto classDeclaration2 = Node::make<ClassDeclaration>(classSymbol2); auto classDeclarationNode2 = Node::cast<Node>(classDeclaration2); auto [module, moduleSourceFile] = createModule(); moduleSourceFile->append(includeStatementNode, SourceFile::Section::HEADERS); moduleSourceFile->append(constantDeclarationNode1, SourceFile::Section::PROPERTIES); moduleSourceFile->append(constantDeclarationNode2, SourceFile::Section::PROPERTIES); moduleSourceFile->append(functionDeclarationNode1, SourceFile::Section::FUNCTIONS); moduleSourceFile->append(functionDeclarationNode2, SourceFile::Section::FUNCTIONS); moduleSourceFile->append(classDeclarationNode1, SourceFile::Section::CLASSES); moduleSourceFile->append(classDeclarationNode2, SourceFile::Section::CLASSES); auto [package, packageSourceFile] = translate(module); auto result = packageSourceFile.sourceCode; // Then EXPECT_STREQ(result.c_str(), expected.c_str()); }