@@ -336,3 +336,46 @@ TEST_F(ListBlocksTest, ItemOfList)
336336 ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
337337 ASSERT_EQ (list->toString (), " Lorem ipsum dolor 123 true" );
338338}
339+
340+ TEST_F (ListBlocksTest, ItemNumOfList)
341+ {
342+ auto target = std::make_shared<Sprite>();
343+
344+ auto list = std::make_shared<List>(" list" , " " );
345+ list->append (" Lorem" );
346+ list->append (" ipsum" );
347+ list->append (" dolor" );
348+ list->append (123 );
349+ list->append (true );
350+ list->append (" dolor" );
351+ target->addList (list);
352+
353+ ScriptBuilder builder (m_extension.get (), m_engine, target);
354+
355+ auto addTest = [&builder](const Value &item, std::shared_ptr<List> list) {
356+ builder.addBlock (" data_itemnumoflist" );
357+ builder.addValueInput (" ITEM" , item);
358+ builder.addEntityField (" LIST" , list);
359+ auto block = builder.takeBlock ();
360+
361+ builder.addBlock (" test_print" );
362+ builder.addObscuredInput (" STRING" , block);
363+ return builder.currentBlock ();
364+ };
365+
366+ auto block = addTest (" dolor" , list);
367+ addTest (true , list);
368+ addTest (" nonexistent" , list);
369+
370+ builder.build ();
371+
372+ static const std::string expected =
373+ " 3\n "
374+ " 5\n "
375+ " 0\n " ;
376+
377+ testing::internal::CaptureStdout ();
378+ builder.run ();
379+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
380+ ASSERT_EQ (list->toString (), " Lorem ipsum dolor 123 true dolor" );
381+ }
0 commit comments