@@ -109,6 +109,7 @@ TEST_F(LooksBlocksTest, RegisterBlocks)
109109 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_sayforsecs" , &LooksBlocks::compileSayForSecs));
110110 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_say" , &LooksBlocks::compileSay));
111111 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_thinkforsecs" , &LooksBlocks::compileThinkForSecs));
112+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_think" , &LooksBlocks::compileThink));
112113 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_show" , &LooksBlocks::compileShow));
113114 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_hide" , &LooksBlocks::compileHide));
114115 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " looks_changeeffectby" , &LooksBlocks::compileChangeEffectBy));
@@ -395,9 +396,9 @@ TEST_F(LooksBlocksTest, ThinkForSecs)
395396TEST_F (LooksBlocksTest, ThinkForSecsImpl)
396397{
397398 static unsigned int bytecode1[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_CONST, 1 , vm::OP_EXEC, 0 , vm::OP_EXEC, 1 , vm::OP_HALT };
398- // static unsigned int bytecode2[] = { vm::OP_START, vm::OP_CONST, 2, vm::OP_EXEC, 2, vm::OP_HALT };
399+ static unsigned int bytecode2[] = { vm::OP_START, vm::OP_CONST, 2 , vm::OP_EXEC, 2 , vm::OP_HALT };
399400 static unsigned int bytecode3[] = { vm::OP_START, vm::OP_CONST, 2 , vm::OP_CONST, 1 , vm::OP_EXEC, 0 , vm::OP_EXEC, 1 , vm::OP_HALT };
400- static BlockFunc functions[] = { &LooksBlocks::startThinkForSecs, &LooksBlocks::thinkForSecs /* , &LooksBlocks::think*/ };
401+ static BlockFunc functions[] = { &LooksBlocks::startThinkForSecs, &LooksBlocks::thinkForSecs, &LooksBlocks::think };
401402 static Value constValues[] = { " test" , 5.5 , " hello" };
402403
403404 Target target;
@@ -452,7 +453,7 @@ TEST_F(LooksBlocksTest, ThinkForSecsImpl)
452453 ASSERT_TRUE (target.bubbleText ().empty ());
453454
454455 // Run the say block while waiting
455- /* VirtualMachine vm2(&target, &m_engineMock, nullptr);
456+ VirtualMachine vm2 (&target, &m_engineMock, nullptr );
456457 vm2.setFunctions (functions);
457458 vm2.setConstValues (constValues);
458459 vm2.setBytecode (bytecode2);
@@ -526,11 +527,57 @@ TEST_F(LooksBlocksTest, ThinkForSecsImpl)
526527 ASSERT_TRUE (LooksBlocks::m_timeMap.find (&vm2) == LooksBlocks::m_timeMap.cend ());
527528 ASSERT_TRUE (vm2.atEnd ());
528529 ASSERT_EQ (target.bubbleType (), Target::BubbleType::Think);
529- ASSERT_EQ(target.bubbleText(), "test");*/
530+ ASSERT_EQ (target.bubbleText (), " test" );
530531
531532 LooksBlocks::clock = Clock::instance ().get ();
532533}
533534
535+ TEST_F (LooksBlocksTest, Think)
536+ {
537+ Compiler compiler (&m_engineMock);
538+
539+ // say "Hmm..."
540+ auto block = std::make_shared<Block>(" a" , " looks_think" );
541+ addValueInput (block, " MESSAGE" , LooksBlocks::MESSAGE, " Hmm..." );
542+
543+ EXPECT_CALL (m_engineMock, functionIndex (&LooksBlocks::think)).WillOnce (Return (0 ));
544+
545+ compiler.init ();
546+ compiler.setBlock (block);
547+ LooksBlocks::compileThink (&compiler);
548+ compiler.end ();
549+
550+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT }));
551+ ASSERT_EQ (compiler.constValues ().size (), 1 );
552+ ASSERT_EQ (compiler.constValues ()[0 ].toString (), " Hmm..." );
553+ }
554+
555+ TEST_F (LooksBlocksTest, ThinkImpl)
556+ {
557+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
558+ static BlockFunc functions[] = { &LooksBlocks::think };
559+ static Value constValues[] = { " test" };
560+
561+ Target target;
562+ VirtualMachine vm (&target, nullptr , nullptr );
563+ vm.setBytecode (bytecode);
564+ vm.setFunctions (functions);
565+ vm.setConstValues (constValues);
566+ vm.run ();
567+
568+ ASSERT_EQ (vm.registerCount (), 0 );
569+ ASSERT_EQ (target.bubbleType (), Target::BubbleType::Think);
570+ ASSERT_EQ (target.bubbleText (), " test" );
571+
572+ target.setBubbleType (Target::BubbleType::Say);
573+ vm.reset ();
574+ vm.run ();
575+
576+ ASSERT_EQ (vm.registerCount (), 0 );
577+ ASSERT_EQ (target.bubbleType (), Target::BubbleType::Think);
578+ ASSERT_EQ (target.bubbleText (), " test" );
579+ }
580+
534581TEST_F (LooksBlocksTest, Show)
535582{
536583 Compiler compiler (&m_engineMock);
0 commit comments