From 0ea69e8d6055faad9ae97986be4c0afaa6d2cbec Mon Sep 17 00:00:00 2001 From: arakov Date: Thu, 28 Mar 2024 21:18:47 +0100 Subject: [PATCH] #637 : supporting google tests --- elenasrc3/elena-tests/bt_optimization.cpp | 13 ++++++++++- elenasrc3/elena-tests/bt_optimization.h | 11 ++++++++-- elenasrc3/elena-tests/bt_tests.cpp | 2 +- elenasrc3/elena-tests/compiler_tests.cpp | 22 ++++++++++++------- elenasrc3/elena-tests/elena-tests.vcxproj | 8 ++++++- .../{common.cpp => tests_common.cpp} | 7 +++++- .../elena-tests/{common.h => tests_common.h} | 4 ++++ elenasrc3/engine/buildtree.h | 6 +++++ 8 files changed, 59 insertions(+), 14 deletions(-) rename elenasrc3/elena-tests/{common.cpp => tests_common.cpp} (84%) rename elenasrc3/elena-tests/{common.h => tests_common.h} (90%) diff --git a/elenasrc3/elena-tests/bt_optimization.cpp b/elenasrc3/elena-tests/bt_optimization.cpp index 1d9f38c57..28668ee4c 100644 --- a/elenasrc3/elena-tests/bt_optimization.cpp +++ b/elenasrc3/elena-tests/bt_optimization.cpp @@ -1 +1,12 @@ -#include "pch.h" +//--------------------------------------------------------------------------- +// E L E N A P r o j e c t: ELENA Compiler +// +// This header contains ELENA Test Optimization Fixture implementation +// (C)2024, by Aleksey Rakov +//--------------------------------------------------------------------------- + +#include "bt_optimization.h" + +using namespace elena_lang; + +// --- BTOptimization1 --- diff --git a/elenasrc3/elena-tests/bt_optimization.h b/elenasrc3/elena-tests/bt_optimization.h index 969e66cdb..316be7af4 100644 --- a/elenasrc3/elena-tests/bt_optimization.h +++ b/elenasrc3/elena-tests/bt_optimization.h @@ -8,13 +8,20 @@ #ifndef BTOPTIMIZATION_H #define BTOPTIMIZATION_H -#include "common.h" +#include "pch.h" +#include "tests_common.h" namespace elena_lang { - class BTOptimization1 : public testing::Test + // Optimization 1 (byRefOp) : "a := b.get()" => "b.get(ref a)" + class BTOptimization1_1 : public testing::Test { protected: + SyntaxTree syntaxTree; + BuildTree buildTree; + + CompilerEnvironment env; + void SetUp() override { } diff --git a/elenasrc3/elena-tests/bt_tests.cpp b/elenasrc3/elena-tests/bt_tests.cpp index c6bc1c797..656e4a59a 100644 --- a/elenasrc3/elena-tests/bt_tests.cpp +++ b/elenasrc3/elena-tests/bt_tests.cpp @@ -2,7 +2,7 @@ #include "bt_optimization.h" using namespace elena_lang; -TEST_F(BTOptimization1, BuildTapeTest) { +TEST_F(BTOptimization1_1, BuildTapeTest) { EXPECT_EQ(1, 1); EXPECT_TRUE(true); } \ No newline at end of file diff --git a/elenasrc3/elena-tests/compiler_tests.cpp b/elenasrc3/elena-tests/compiler_tests.cpp index 27a52cb8a..f57868091 100644 --- a/elenasrc3/elena-tests/compiler_tests.cpp +++ b/elenasrc3/elena-tests/compiler_tests.cpp @@ -2,18 +2,24 @@ // ------------------------------------------------ #include "bt_optimization.h" -//#include "elena.h" - -#include "common.h" +#include "compiler.h" using namespace elena_lang; -TEST_F(BTOptimization1, CompilerTest) { +TEST_F(BTOptimization1_1, CompilerTest) +{ + // Arrange + Compiler* compiler = env.createCompiler(); - CompilerEnvironment env; + BuildTree output; + BuildTreeWriter writer(output); + Compiler::SymbolScope rootScope(nullptr, 0, Visibility::Internal); + Compiler::Expression expression(compiler, rootScope, writer); - //Compiler* compiler = /*env.createCompiler()*/nullptr; + // Act + expression.compileRoot(syntaxTree.readRoot(), ExpressionAttribute::None); - EXPECT_EQ(1, 1); - EXPECT_TRUE(true); + // Assess + bool matched = BuildTree::compare(buildTree.readRoot(), output.readRoot()); + EXPECT_TRUE(matched); } \ No newline at end of file diff --git a/elenasrc3/elena-tests/elena-tests.vcxproj b/elenasrc3/elena-tests/elena-tests.vcxproj index 733adc20a..4432a2bf4 100644 --- a/elenasrc3/elena-tests/elena-tests.vcxproj +++ b/elenasrc3/elena-tests/elena-tests.vcxproj @@ -62,7 +62,7 @@ EnableFastChecks MultiThreadedDebugDLL Level3 - ..\common;..\engine;%(AdditionalIncludeDirectories) + ..\elc;..\common;..\engine;%(AdditionalIncludeDirectories) Default stdc17 @@ -127,6 +127,12 @@ + + + + + + diff --git a/elenasrc3/elena-tests/common.cpp b/elenasrc3/elena-tests/tests_common.cpp similarity index 84% rename from elenasrc3/elena-tests/common.cpp rename to elenasrc3/elena-tests/tests_common.cpp index a682f3afd..1d39b26dc 100644 --- a/elenasrc3/elena-tests/common.cpp +++ b/elenasrc3/elena-tests/tests_common.cpp @@ -8,7 +8,7 @@ #include "pch.h" // -------------------------------------------------------------------------- -#include "common.h" +#include "tests_common.h" using namespace elena_lang; @@ -17,4 +17,9 @@ using namespace elena_lang; CompilerEnvironment :: CompilerEnvironment() { +} + +Compiler* CompilerEnvironment :: createCompiler() +{ + return nullptr; } \ No newline at end of file diff --git a/elenasrc3/elena-tests/common.h b/elenasrc3/elena-tests/tests_common.h similarity index 90% rename from elenasrc3/elena-tests/common.h rename to elenasrc3/elena-tests/tests_common.h index 5a2d8e1e1..9d04a3b13 100644 --- a/elenasrc3/elena-tests/common.h +++ b/elenasrc3/elena-tests/tests_common.h @@ -8,12 +8,16 @@ #ifndef TESTS_COMMON_H #define TESTS_COMMON_H +#include "compiler.h" + namespace elena_lang { // --- CompilerEnvironment --- class CompilerEnvironment { public: + Compiler* createCompiler(); + CompilerEnvironment(); }; } diff --git a/elenasrc3/engine/buildtree.h b/elenasrc3/engine/buildtree.h index 2937db4f7..3bc3b5a89 100644 --- a/elenasrc3/engine/buildtree.h +++ b/elenasrc3/engine/buildtree.h @@ -241,6 +241,12 @@ namespace elena_lang class BuildTree : public Tree { public: + static bool compare(Tree::Node n1, Tree::Node n2) + { + // !! temporal + return false; + } + static pos_t countChildren(Tree::Node node, BuildKey mask) { pos_t counter = 0;