Skip to content

Commit 5be3db3

Browse files
committed
Add text for syntax error
Mainly due to memory leaks being reported happening in case of parsing errors.
1 parent 0290017 commit 5be3db3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ add_executable(projectM_EvalLib_Test
77
PrecedenceTest.cpp
88
PrecedenceTest.hpp
99
Stubs.cpp
10+
SyntaxTest.cpp
11+
SyntaxTest.hpp
1012
TreeFunctionsTest.cpp
1113
)
1214

tests/SyntaxTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "SyntaxTest.hpp"
2+
3+
4+
void SyntaxTest::SetUp()
5+
{
6+
m_globalMemory = projectm_eval_memory_buffer_create();
7+
m_context = projectm_eval_context_create(m_globalMemory, &m_globalRegisters);
8+
}
9+
10+
void SyntaxTest::TearDown()
11+
{
12+
projectm_eval_context_destroy(m_context);
13+
projectm_eval_memory_buffer_destroy(m_globalMemory);
14+
memset(&m_globalRegisters, 0, sizeof(m_globalRegisters));
15+
}
16+
17+
TEST_F(SyntaxTest, AdditionalLineBreak)
18+
{
19+
auto code = projectm_eval_code_compile(m_context, "k1 = is_\nbeat*equal(index%2,0);");
20+
21+
ASSERT_EQ(code, nullptr);
22+
ASSERT_STREQ(projectm_eval_get_error(m_context, nullptr, nullptr), "syntax error, unexpected VAR");
23+
}

tests/SyntaxTest.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <gtest/gtest.h>
4+
5+
#include <projectm-eval/api/projectm-eval.h>
6+
7+
class SyntaxTest : public testing::Test
8+
{
9+
public:
10+
11+
protected:
12+
13+
void SetUp() override;
14+
15+
void TearDown() override;
16+
17+
struct projectm_eval_context* m_context{};
18+
projectm_eval_mem_buffer m_globalMemory{};
19+
PRJM_EVAL_F m_globalRegisters[100]{};
20+
};

0 commit comments

Comments
 (0)