File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff 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
2930CompilerValue *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+ }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments