Skip to content

Commit b976f53

Browse files
committed
Implement data_deletealloflist
1 parent 545df0c commit b976f53

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/dev/blocks/listblocks.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void ListBlocks::registerBlocks(IEngine *engine)
2424
{
2525
engine->addCompileFunction(this, "data_addtolist", &compileAddToList);
2626
engine->addCompileFunction(this, "data_deleteoflist", &compileDeleteOfList);
27+
engine->addCompileFunction(this, "data_deletealloflist", &compileDeleteAllOfList);
2728
}
2829

2930
CompilerValue *ListBlocks::compileAddToList(Compiler *compiler)
@@ -91,3 +92,14 @@ CompilerValue *ListBlocks::compileDeleteOfList(Compiler *compiler)
9192

9293
return nullptr;
9394
}
95+
96+
CompilerValue *ListBlocks::compileDeleteAllOfList(Compiler *compiler)
97+
{
98+
auto list = compiler->field("LIST")->valuePtr();
99+
assert(list);
100+
101+
if (list)
102+
compiler->createListClear(static_cast<List *>(list.get()));
103+
104+
return nullptr;
105+
}

test/dev/blocks/list_blocks_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,24 @@ TEST_F(ListBlocksTest, DeleteOfList)
133133
ASSERT_EQ(list2->toString(), "Hello false abc");
134134
ASSERT_TRUE(list3->empty());
135135
}
136+
137+
TEST_F(ListBlocksTest, DeleteAllOfList)
138+
{
139+
auto target = std::make_shared<Sprite>();
140+
141+
auto list = std::make_shared<List>("", "");
142+
list->append("Lorem");
143+
list->append("ipsum");
144+
list->append("dolor");
145+
list->append(123);
146+
list->append(true);
147+
target->addList(list);
148+
149+
ScriptBuilder builder(m_extension.get(), m_engine, target);
150+
builder.addBlock("data_deletealloflist");
151+
builder.addEntityField("LIST", list);
152+
builder.build();
153+
154+
builder.run();
155+
ASSERT_TRUE(list->empty());
156+
}

0 commit comments

Comments
 (0)