@@ -2190,6 +2190,75 @@ TEST_F(LLVMCodeBuilderTest, ListReplace)
21902190 ASSERT_EQ (localList->toString (), " 3 ipsum true hello world" );
21912191}
21922192
2193+ TEST_F (LLVMCodeBuilderTest, GetListItem)
2194+ {
2195+ EngineMock engine;
2196+ Stage stage;
2197+ Sprite sprite;
2198+ sprite.setEngine (&engine);
2199+ EXPECT_CALL (engine, stage ()).WillRepeatedly (Return (&stage));
2200+
2201+ std::unordered_map<List *, std::string> strings;
2202+
2203+ auto globalList = std::make_shared<List>(" " , " " );
2204+ stage.addList (globalList);
2205+
2206+ auto localList = std::make_shared<List>(" " , " " );
2207+ sprite.addList (localList);
2208+
2209+ globalList->append (1 );
2210+ globalList->append (2 );
2211+ globalList->append (3 );
2212+
2213+ localList->append (" Lorem" );
2214+ localList->append (" ipsum" );
2215+ localList->append (" dolor" );
2216+ localList->append (" sit" );
2217+ strings[localList.get ()] = localList->toString ();
2218+
2219+ createBuilder (&sprite, true );
2220+
2221+ m_builder->addConstValue (2 );
2222+ m_builder->addListItem (globalList.get ());
2223+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
2224+
2225+ m_builder->addConstValue (1 );
2226+ m_builder->addConstValue (" test" );
2227+ m_builder->createListReplace (globalList.get ());
2228+
2229+ m_builder->addConstValue (0 );
2230+ m_builder->addListItem (globalList.get ());
2231+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
2232+
2233+ m_builder->addConstValue (0 );
2234+ m_builder->addListItem (localList.get ());
2235+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
2236+
2237+ m_builder->addConstValue (2 );
2238+ m_builder->addListItem (localList.get ());
2239+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
2240+
2241+ m_builder->addConstValue (3 );
2242+ m_builder->addListItem (localList.get ());
2243+ m_builder->addFunctionCall (" test_print_string" , Compiler::StaticType::Void, { Compiler::StaticType::String });
2244+
2245+ static const std::string expected =
2246+ " 3\n "
2247+ " 1\n "
2248+ " Lorem\n "
2249+ " dolor\n "
2250+ " sit\n " ;
2251+
2252+ auto code = m_builder->finalize ();
2253+ auto ctx = code->createExecutionContext (&sprite);
2254+ testing::internal::CaptureStdout ();
2255+ code->run (ctx.get ());
2256+ ASSERT_EQ (testing::internal::GetCapturedStdout (), expected);
2257+
2258+ ASSERT_EQ (globalList->toString (), " 1 test 3" );
2259+ ASSERT_EQ (localList->toString (), " Lorem ipsum dolor sit" );
2260+ }
2261+
21932262TEST_F (LLVMCodeBuilderTest, Yield)
21942263{
21952264 auto build = [this ]() {
0 commit comments