@@ -104,6 +104,7 @@ TEST_F(LooksBlocksTest, CategoryVisible)
104104TEST_F (LooksBlocksTest, RegisterBlocks)
105105{
106106 // Blocks
107+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_say" , &LooksBlocks::compileSay));
107108 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_show" , &LooksBlocks::compileShow));
108109 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_hide" , &LooksBlocks::compileHide));
109110 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_changeeffectby" , &LooksBlocks::compileChangeEffectBy));
@@ -128,6 +129,7 @@ TEST_F(LooksBlocksTest, RegisterBlocks)
128129 EXPECT_CALL (m_engineMock, addMonitorNameFunction (m_section.get (), " looks_size" , &LooksBlocks::sizeMonitorName));
129130
130131 // Inputs
132+ EXPECT_CALL (m_engineMock, addInput (m_section.get (), " MESSAGE" , LooksBlocks::MESSAGE));
131133 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " CHANGE" , LooksBlocks::CHANGE));
132134 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " SIZE" , LooksBlocks::SIZE));
133135 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " COSTUME" , LooksBlocks::COSTUME));
@@ -158,6 +160,52 @@ TEST_F(LooksBlocksTest, RegisterBlocks)
158160 m_section->registerBlocks (&m_engineMock);
159161}
160162
163+ TEST_F (LooksBlocksTest, Say)
164+ {
165+ Compiler compiler (&m_engineMock);
166+
167+ // say "Hello!"
168+ auto block = std::make_shared<Block>(" a" , " looks_say" );
169+ addValueInput (block, " MESSAGE" , LooksBlocks::MESSAGE, " Hello!" );
170+
171+ EXPECT_CALL (m_engineMock, functionIndex (&LooksBlocks::say)).WillOnce (Return (0 ));
172+
173+ compiler.init ();
174+ compiler.setBlock (block);
175+ LooksBlocks::compileSay (&compiler);
176+ compiler.end ();
177+
178+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT }));
179+ ASSERT_EQ (compiler.constValues ().size (), 1 );
180+ ASSERT_EQ (compiler.constValues ()[0 ].toString (), " Hello!" );
181+ }
182+
183+ TEST_F (LooksBlocksTest, SayImpl)
184+ {
185+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
186+ static BlockFunc functions[] = { &LooksBlocks::say };
187+ static Value constValues[] = { " test" };
188+
189+ Target target;
190+ VirtualMachine vm (&target, nullptr , nullptr );
191+ vm.setBytecode (bytecode);
192+ vm.setFunctions (functions);
193+ vm.setConstValues (constValues);
194+ vm.run ();
195+
196+ ASSERT_EQ (vm.registerCount (), 0 );
197+ ASSERT_EQ (target.bubbleType (), Target::BubbleType::Say);
198+ ASSERT_EQ (target.bubbleText (), " test" );
199+
200+ target.setBubbleType (Target::BubbleType::Think);
201+ vm.reset ();
202+ vm.run ();
203+
204+ ASSERT_EQ (vm.registerCount (), 0 );
205+ ASSERT_EQ (target.bubbleType (), Target::BubbleType::Say);
206+ ASSERT_EQ (target.bubbleText (), " test" );
207+ }
208+
161209TEST_F (LooksBlocksTest, Show)
162210{
163211 Compiler compiler (&m_engineMock);
0 commit comments