@@ -211,3 +211,59 @@ TEST_F(ListBlocksTest, InsertAtList)
211211 ASSERT_EQ (list1->toString (), " Lorem ipsum dolor sit 123 true false" );
212212 ASSERT_EQ (list2->toString (), " Hello world dolor false -543.5 abc 52.4 lorem ipsum" );
213213}
214+
215+ TEST_F (ListBlocksTest, ReplaceItemOfList)
216+ {
217+ auto target = std::make_shared<Sprite>();
218+
219+ auto list1 = std::make_shared<List>(" " , " " );
220+ list1->append (" Lorem" );
221+ list1->append (" ipsum" );
222+ list1->append (" dolor" );
223+ list1->append (123 );
224+ list1->append (true );
225+ target->addList (list1);
226+
227+ auto list2 = std::make_shared<List>(" " , " " );
228+ list2->append (" Hello" );
229+ list2->append (" world" );
230+ list2->append (false );
231+ list2->append (-543.5 );
232+ list2->append (" abc" );
233+ list2->append (52.4 );
234+ target->addList (list2);
235+
236+ ScriptBuilder builder (m_extension.get (), m_engine, target);
237+
238+ auto addTest = [&builder](const Value &index, const Value &item, std::shared_ptr<List> list) {
239+ builder.addBlock (" data_replaceitemoflist" );
240+ builder.addValueInput (" INDEX" , index);
241+ builder.addEntityField (" LIST" , list);
242+ builder.addValueInput (" ITEM" , item);
243+ return builder.currentBlock ();
244+ };
245+
246+ auto block = addTest (4 , " sit" , list1);
247+ addTest (5 , -53.18 , list1);
248+ addTest (0 , " test" , list1);
249+ addTest (6 , " test" , list1);
250+
251+ addTest (" last" , " lorem" , list2);
252+ addTest (" random" , " ipsum" , list2);
253+ addTest (" any" , " dolor" , list2);
254+
255+ builder.build ();
256+
257+ Compiler compiler (&m_engineMock, target.get ());
258+ auto code = compiler.compile (block);
259+ Script script (target.get (), block, &m_engineMock);
260+ script.setCode (code);
261+ Thread thread (target.get (), &m_engineMock, &script);
262+ auto ctx = code->createExecutionContext (&thread);
263+ ctx->setRng (&m_rng);
264+
265+ EXPECT_CALL (m_rng, randint (1 , 6 )).WillOnce (Return (4 )).WillOnce (Return (1 ));
266+ code->run (ctx.get ());
267+ ASSERT_EQ (list1->toString (), " Lorem ipsum dolor sit -53.18" );
268+ ASSERT_EQ (list2->toString (), " dolor world false ipsum abc lorem" );
269+ }
0 commit comments