@@ -45,11 +45,10 @@ class CompilerTest : public testing::Test
4545 m_testVar.reset ();
4646 }
4747
48- void compile (Compiler *compiler, std::shared_ptr<Block> block)
48+ void compile (Compiler *compiler, std::shared_ptr<Block> block, BlockPrototype *procedurePrototype = nullptr )
4949 {
5050 ASSERT_EQ (compiler->block (), nullptr );
51- // TODO: Test procedures
52- EXPECT_CALL (m_builderFactory, create (m_ctx.get (), nullptr )).WillOnce (Return (m_builder));
51+ EXPECT_CALL (m_builderFactory, create (m_ctx.get (), procedurePrototype)).WillOnce (Return (m_builder));
5352 EXPECT_CALL (*m_builder, finalize ()).WillOnce (Return (m_code));
5453 ASSERT_EQ (compiler->compile (block), m_code);
5554 ASSERT_EQ (compiler->block (), nullptr );
@@ -338,6 +337,25 @@ TEST_F(CompilerTest, AddListContains)
338337 compile (m_compiler.get (), block);
339338}
340339
340+ TEST_F (CompilerTest, AddProcedureArgument)
341+ {
342+
343+ auto block = std::make_shared<Block>(" a" , " " );
344+ block->setCompileFunction ([](Compiler *compiler) -> CompilerValue * {
345+ CompilerValue ret (Compiler::StaticType::Unknown);
346+
347+ EXPECT_CALL (*m_builder, addProcedureArgument (" arg 1" )).WillOnce (Return (&ret));
348+ EXPECT_EQ (compiler->addProcedureArgument (" arg 1" ), &ret);
349+
350+ EXPECT_CALL (*m_builder, addProcedureArgument (" arg 2" )).WillOnce (Return (nullptr ));
351+ EXPECT_EQ (compiler->addProcedureArgument (" arg 2" ), nullptr );
352+
353+ return nullptr ;
354+ });
355+
356+ compile (m_compiler.get (), block);
357+ }
358+
341359TEST_F (CompilerTest, AddInput)
342360{
343361
@@ -1572,6 +1590,25 @@ TEST_F(CompilerTest, CreateStop)
15721590 compile (m_compiler.get (), block);
15731591}
15741592
1593+ TEST_F (CompilerTest, CreateProcedureCall)
1594+ {
1595+
1596+ auto block = std::make_shared<Block>(" " , " " );
1597+
1598+ block->setCompileFunction ([](Compiler *compiler) -> CompilerValue * {
1599+ BlockPrototype prototype;
1600+ CompilerValue arg1 (Compiler::StaticType::Unknown);
1601+ CompilerValue arg2 (Compiler::StaticType::Unknown);
1602+ Compiler::Args args = { &arg1, &arg2 };
1603+
1604+ EXPECT_CALL (*m_builder, createProcedureCall (&prototype, args));
1605+ compiler->createProcedureCall (&prototype, args);
1606+ return nullptr ;
1607+ });
1608+
1609+ compile (m_compiler.get (), block);
1610+ }
1611+
15751612TEST_F (CompilerTest, Input)
15761613{
15771614
@@ -1660,3 +1697,30 @@ TEST_F(CompilerTest, UnsupportedBlocks)
16601697
16611698 ASSERT_EQ (m_compiler->unsupportedBlocks (), std::unordered_set<std::string>({ " block1" , " block2" , " value_block1" , " value_block3" , " value_block5" , " block4" }));
16621699}
1700+
1701+ TEST_F (CompilerTest, Procedure)
1702+ {
1703+ {
1704+ auto block = std::make_shared<Block>(" " , " " );
1705+ auto customBlock = std::make_shared<Block>(" " , " " );
1706+ customBlock->mutationPrototype ()->setProcCode (" " );
1707+
1708+ auto input = std::make_shared<Input>(" custom_block" , Input::Type::ObscuredShadow);
1709+ input->setValueBlock (customBlock);
1710+ block->addInput (input);
1711+
1712+ compile (m_compiler.get (), block, nullptr );
1713+ }
1714+
1715+ {
1716+ auto block = std::make_shared<Block>(" " , " " );
1717+ auto customBlock = std::make_shared<Block>(" " , " " );
1718+ customBlock->mutationPrototype ()->setProcCode (" test" );
1719+
1720+ auto input = std::make_shared<Input>(" custom_block" , Input::Type::ObscuredShadow);
1721+ input->setValueBlock (customBlock);
1722+ block->addInput (input);
1723+
1724+ compile (m_compiler.get (), block, customBlock->mutationPrototype ());
1725+ }
1726+ }
0 commit comments