Skip to content

Commit 24b98b2

Browse files
committed
Implement procedures_definition
1 parent cbc81a6 commit 24b98b2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/dev/blocks/customblocks.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
#include <scratchcpp/iengine.h>
4+
#include <scratchcpp/dev/compiler.h>
5+
36
#include "customblocks.h"
47

58
using namespace libscratchcpp;
@@ -16,4 +19,5 @@ std::string CustomBlocks::description() const
1619

1720
void CustomBlocks::registerBlocks(IEngine *engine)
1821
{
22+
engine->addCompileFunction(this, "procedures_definition", [](Compiler *) -> CompilerValue * { return nullptr; });
1923
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
1+
#include <scratchcpp/project.h>
2+
#include <scratchcpp/dev/test/scriptbuilder.h>
3+
#include <scratchcpp/dev/compiler.h>
4+
#include <scratchcpp/sprite.h>
15
#include <enginemock.h>
26

37
#include "../common.h"
48
#include "dev/blocks/customblocks.h"
59

610
using namespace libscratchcpp;
11+
using namespace libscratchcpp::test;
712

813
class CustomBlocksTest : public testing::Test
914
{
1015
public:
11-
void SetUp() override { m_extension = std::make_unique<CustomBlocks>(); }
16+
void SetUp() override
17+
{
18+
m_extension = std::make_unique<CustomBlocks>();
19+
m_engine = m_project.engine().get();
20+
m_extension->registerBlocks(m_engine);
21+
}
1222

1323
std::unique_ptr<IExtension> m_extension;
24+
Project m_project;
25+
IEngine *m_engine = nullptr;
1426
EngineMock m_engineMock;
1527
};
28+
29+
TEST_F(CustomBlocksTest, Definition)
30+
{
31+
auto target = std::make_shared<Sprite>();
32+
ScriptBuilder builder(m_extension.get(), m_engine, target);
33+
34+
builder.addBlock("procedures_definition");
35+
auto block = builder.currentBlock();
36+
37+
Compiler compiler(&m_engineMock, target.get());
38+
compiler.compile(block);
39+
ASSERT_TRUE(compiler.unsupportedBlocks().empty());
40+
}

0 commit comments

Comments
 (0)