Skip to content

Commit

Permalink
#637 : working on unit test support
Browse files Browse the repository at this point in the history
  • Loading branch information
arakov committed Mar 27, 2024
1 parent 0c6844d commit 4659999
Show file tree
Hide file tree
Showing 24 changed files with 308 additions and 31 deletions.
10 changes: 8 additions & 2 deletions doc/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ In development:
port:win64 gui,helloworld gui sample (button), chat sample, win64 script samples
--------------------------------------
- #617
- #637 : all bt tests
--------------------------------------
- #637
- serialize / deserialize tree : syntax tree
- serialize / deserialize tree : build tree

- #637 : ByRefOpMark - message, property, weak operation

- remove Serializer / ScriptReader from elc project (when no longer is required)

- port : rest of system module from lib50

=== Iteration 22 ===
--------------------------------------
dev: async programming (instant messagange sample (chat) ), #608
dev: async programming (instant messagange sample (chat) ), #608, #637 (all bc tests)
op:
opt:pi under 6 sec, #601
maint: #506
Expand Down
9 changes: 8 additions & 1 deletion elenasrc3/common/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This file contains the implementation of ELENA Engine Data Section
// classes.
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#include "common.h"
Expand Down Expand Up @@ -152,3 +152,10 @@ bool ByteArray :: insert(pos_t position, const void* s, pos_t length)
void ByteArray :: trim(pos_t position)
{
}

// --- DynamicUStrWriter ---

DynamicUStrWriter::DynamicUStrWriter(DynamicUStr* target)
{
_target = target;
}
42 changes: 41 additions & 1 deletion elenasrc3/common/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This header contains the declaration of ELENA Engine Data Memory dump
// classes.
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef DUMP_H
Expand Down Expand Up @@ -141,6 +141,46 @@ namespace elena_lang
}
};

// --- DynamicUStrWriter ---
class DynamicUStrWriter : public TextWriter<char>
{
DynamicUStr* _target;

public:
bool isOpen() const override { return true; }

pos_t position() const override { return _target->length_pos(); }

bool seek(pos_t position)
{
if (_target->length_pos() < position)
return false;

_target->trim(position);
return true;
}

bool writeNewLine() override
{
char ch = '\n';

return write(&ch, 1);
}

bool write(const char* s, pos_t length)
{
_target->append(s, length);

return true;
}

void reset()
{
_target->clear();
}

DynamicUStrWriter(DynamicUStr* target);
};
}

#endif // DUMP_H
32 changes: 31 additions & 1 deletion elenasrc3/common/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This file contains ELENA Tree template classes
//
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef TREE_H
Expand Down Expand Up @@ -720,6 +720,36 @@ namespace elena_lang
return counter;
}

static void serialize(Node& node, void(*encoder)(TextWriter<char>&, Key, ustr_t, int, void*), TextWriter<char>& writer, void* arg)
{
encoder(writer, node.key, node.identifier(), node.arg.value, arg);
Node current = node.firstChild();
while (current != defKey) {
serialize(current, encoder, writer, arg);

current = current.nextNode();
}

encoder(writer, defKey, nullptr, 0, nullptr);
}

static void deserialize(Node root, bool(*reader)(Key&, IdentifierString&, int&, void*), void* arg)
{
Key key = defKey;
IdentifierString strArg;
int intArg;

Node current = {};
while (reader(key, strArg, intArg, arg)) {
if (strArg.length() > 0) {
current = root.appendChild(key, *strArg);
}
else current = root.appendChild(key, intArg);

deserialize(current, reader, arg);
}
}

Tree() = default;
};
}
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/common/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This file contains String classes implementations
//
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
// (C)1994-2004, Unicode, Inc.
//---------------------------------------------------------------------------

Expand Down
9 changes: 8 additions & 1 deletion elenasrc3/common/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This header contains UTF8 String classes declarations
//
// (C)2021-2022, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef USTRING_H
Expand Down Expand Up @@ -675,6 +675,12 @@ namespace elena_lang
_string[0] = 0;
}

void trim(size_t position)
{
if (_string)
_string[position] = 0;
}

DynamicString()
{
_size = 0;
Expand All @@ -690,6 +696,7 @@ namespace elena_lang

};

typedef DynamicString<char> DynamicUStr;
}

#endif // USTRING_H
2 changes: 1 addition & 1 deletion elenasrc3/elc/cliconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace elena_lang
{
#define ELC_REVISION_NUMBER 0x0244
#define ELC_REVISION_NUMBER 0x0245

#if defined _M_IX86 || _M_X64

Expand Down
4 changes: 4 additions & 0 deletions elenasrc3/elc/vs/elc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@
<ClCompile Include="..\..\engine\libman.cpp" />
<ClCompile Include="..\..\engine\module.cpp" />
<ClCompile Include="..\..\engine\parsertable.cpp" />
<ClCompile Include="..\..\engine\scriptreader.cpp" />
<ClCompile Include="..\..\engine\section.cpp" />
<ClCompile Include="..\..\engine\serializer.cpp" />
<ClCompile Include="..\..\engine\syntaxtree.cpp" />
<ClCompile Include="..\..\engine\windows\presenter.cpp" />
<ClCompile Include="..\..\engine\x86compiler.cpp" />
Expand Down Expand Up @@ -232,7 +234,9 @@
<ClInclude Include="..\..\engine\module.h" />
<ClInclude Include="..\..\engine\parsertable.h" />
<ClInclude Include="..\..\engine\projectbase.h" />
<ClInclude Include="..\..\engine\scriptreader.h" />
<ClInclude Include="..\..\engine\section.h" />
<ClInclude Include="..\..\engine\serializer.h" />
<ClInclude Include="..\..\engine\syntaxtree.h" />
<ClInclude Include="..\..\engine\windows\presenter.h" />
<ClInclude Include="..\..\engine\x86compiler.h" />
Expand Down
1 change: 1 addition & 0 deletions elenasrc3/elena-tests/bt_optimization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pch.h"
24 changes: 24 additions & 0 deletions elenasrc3/elena-tests/bt_optimization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA Compiler
//
// This header contains ELENA Test Optimization Fixture declarations
// (C)2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef BTOPTIMIZATION_H
#define BTOPTIMIZATION_H

#include "common.h"

namespace elena_lang
{
class BTOptimization1 : public testing::Test
{
protected:
void SetUp() override
{
}
};
}

#endif
8 changes: 8 additions & 0 deletions elenasrc3/elena-tests/bt_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "pch.h"
#include "bt_optimization.h"

using namespace elena_lang;
TEST_F(BTOptimization1, BuildTapeTest) {
EXPECT_EQ(1, 1);
EXPECT_TRUE(true);
}
1 change: 1 addition & 0 deletions elenasrc3/elena-tests/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pch.h"
11 changes: 11 additions & 0 deletions elenasrc3/elena-tests/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//---------------------------------------------------------------------------
// E L E N A P r o j e c t: ELENA Compiler
//
// This header contains ELENA Test Common declarations
// (C)2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef COMMON_H
#define COMMON_H

#endif
10 changes: 10 additions & 0 deletions elenasrc3/elena-tests/compiler_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "pch.h"
// ------------------------------------------------
#include "bt_optimization.h"

using namespace elena_lang;

TEST_F(BTOptimization1, CompilerTest) {
EXPECT_EQ(1, 1);
EXPECT_TRUE(true);
}
7 changes: 6 additions & 1 deletion elenasrc3/elena-tests/elena-tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="common.h" />
<ClInclude Include="bt_optimization.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="test.cpp" />
<ClCompile Include="common.cpp" />
<ClCompile Include="bt_optimization.cpp" />
<ClCompile Include="compiler_tests.cpp" />
<ClCompile Include="bt_tests.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down
6 changes: 0 additions & 6 deletions elenasrc3/elena-tests/test.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion elenasrc3/engine/bcwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This file contains ELENA byte code writer class.
//
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef BCWRITER_H
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/engine/scriptreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This file contains ELENA ScriptReader class implementation.
//
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#include "elena.h"
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/engine/scriptreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This header contains ELENA Script Reader class declaration.
//
// (C)2021-2023, by Aleksey Rakov
// (C)2021-2024, by Aleksey Rakov
//---------------------------------------------------------------------------

#ifndef SCRIPTREADER_H
Expand Down
Loading

0 comments on commit 4659999

Please sign in to comment.