Skip to content

Commit

Permalink
#637 : supporting google tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arakov committed Mar 28, 2024
1 parent 81096c6 commit 0ea69e8
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
13 changes: 12 additions & 1 deletion elenasrc3/elena-tests/bt_optimization.cpp
Original file line number Diff line number Diff line change
@@ -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 ---
11 changes: 9 additions & 2 deletions elenasrc3/elena-tests/bt_optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/elena-tests/bt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
22 changes: 14 additions & 8 deletions elenasrc3/elena-tests/compiler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 7 additions & 1 deletion elenasrc3/elena-tests/elena-tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>..\common;..\engine;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\elc;..\common;..\engine;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
Expand Down Expand Up @@ -127,6 +127,12 @@
<ClInclude Include="bt_optimization.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\dump.cpp" />
<ClCompile Include="..\common\ustring.cpp" />
<ClCompile Include="..\elc\compiler.cpp" />
<ClCompile Include="..\elc\compilerlogic.cpp" />
<ClCompile Include="..\engine\bytecode.cpp" />
<ClCompile Include="..\engine\syntaxtree.cpp" />
<ClCompile Include="tests_common.cpp" />
<ClCompile Include="bt_optimization.cpp" />
<ClCompile Include="compiler_tests.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "pch.h"
// --------------------------------------------------------------------------
#include "common.h"
#include "tests_common.h"

using namespace elena_lang;

Expand All @@ -17,4 +17,9 @@ using namespace elena_lang;
CompilerEnvironment :: CompilerEnvironment()
{

}

Compiler* CompilerEnvironment :: createCompiler()
{
return nullptr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
Expand Down
6 changes: 6 additions & 0 deletions elenasrc3/engine/buildtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ namespace elena_lang
class BuildTree : public Tree<BuildKey, BuildKey::None>
{
public:
static bool compare(Tree<BuildKey, BuildKey::None>::Node n1, Tree<BuildKey, BuildKey::None>::Node n2)
{
// !! temporal
return false;
}

static pos_t countChildren(Tree<BuildKey, BuildKey::None>::Node node, BuildKey mask)
{
pos_t counter = 0;
Expand Down

0 comments on commit 0ea69e8

Please sign in to comment.