Skip to content

Commit

Permalink
Implement data_deletealloflist
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Dec 28, 2024
1 parent 545df0c commit b976f53
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/dev/blocks/listblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void ListBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "data_addtolist", &compileAddToList);
engine->addCompileFunction(this, "data_deleteoflist", &compileDeleteOfList);
engine->addCompileFunction(this, "data_deletealloflist", &compileDeleteAllOfList);
}

CompilerValue *ListBlocks::compileAddToList(Compiler *compiler)
Expand Down Expand Up @@ -91,3 +92,14 @@ CompilerValue *ListBlocks::compileDeleteOfList(Compiler *compiler)

return nullptr;
}

CompilerValue *ListBlocks::compileDeleteAllOfList(Compiler *compiler)
{
auto list = compiler->field("LIST")->valuePtr();
assert(list);

if (list)
compiler->createListClear(static_cast<List *>(list.get()));

return nullptr;
}
21 changes: 21 additions & 0 deletions test/dev/blocks/list_blocks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,24 @@ TEST_F(ListBlocksTest, DeleteOfList)
ASSERT_EQ(list2->toString(), "Hello false abc");
ASSERT_TRUE(list3->empty());
}

TEST_F(ListBlocksTest, DeleteAllOfList)
{
auto target = std::make_shared<Sprite>();

auto list = std::make_shared<List>("", "");
list->append("Lorem");
list->append("ipsum");
list->append("dolor");
list->append(123);
list->append(true);
target->addList(list);

ScriptBuilder builder(m_extension.get(), m_engine, target);
builder.addBlock("data_deletealloflist");
builder.addEntityField("LIST", list);
builder.build();

builder.run();
ASSERT_TRUE(list->empty());
}

0 comments on commit b976f53

Please sign in to comment.