@@ -46,12 +46,12 @@ class CompilerTest : public testing::Test
4646 m_testVar.reset ();
4747 }
4848
49- void compile (Compiler *compiler, std::shared_ptr<Block> block, BlockPrototype *procedurePrototype = nullptr )
49+ void compile (Compiler *compiler, std::shared_ptr<Block> block, BlockPrototype *procedurePrototype = nullptr , bool isHatPredicate = false )
5050 {
5151 ASSERT_EQ (compiler->block (), nullptr );
52- EXPECT_CALL (m_builderFactory, create (m_ctx.get (), procedurePrototype)).WillOnce (Return (m_builder));
52+ EXPECT_CALL (m_builderFactory, create (m_ctx.get (), procedurePrototype, isHatPredicate )).WillOnce (Return (m_builder));
5353 EXPECT_CALL (*m_builder, finalize ()).WillOnce (Return (m_code));
54- ASSERT_EQ (compiler->compile (block), m_code);
54+ ASSERT_EQ (compiler->compile (block, isHatPredicate ), m_code);
5555 ASSERT_EQ (compiler->block (), nullptr );
5656 }
5757
@@ -1778,7 +1778,23 @@ TEST_F(CompilerTest, UnsupportedBlocks)
17781778 EXPECT_CALL (*m_builder, addConstValue).WillRepeatedly (Return (nullptr ));
17791779 compile (m_compiler.get (), block1);
17801780
1781- ASSERT_EQ (m_compiler->unsupportedBlocks (), std::unordered_set<std::string>({ " block1" , " block2" , " value_block1" , " value_block3" , " value_block5" , " block4" }));
1781+ // Hat predicates
1782+ auto block5 = std::make_shared<Block>(" b5" , " block5" );
1783+ compile (m_compiler.get (), block5, nullptr , true );
1784+
1785+ auto block6 = std::make_shared<Block>(" b6" , " block6" );
1786+ block6->setCompileFunction ([](Compiler *) -> CompilerValue * { return nullptr ; });
1787+ compile (m_compiler.get (), block6, nullptr , true );
1788+
1789+ auto block7 = std::make_shared<Block>(" b7" , " block7" );
1790+ CompilerConstant ret (Compiler::StaticType::Bool, Value (true ));
1791+ block7->setCompileFunction ([](Compiler *) -> CompilerValue * { return nullptr ; });
1792+ block7->setHatPredicateCompileFunction ([](Compiler *compiler) -> CompilerValue * { return compiler->addConstValue (true ); });
1793+ EXPECT_CALL (*m_builder, addConstValue (Value (true ))).WillOnce (Return (&ret));
1794+ compile (m_compiler.get (), block7, nullptr , true );
1795+
1796+ // Check
1797+ ASSERT_EQ (m_compiler->unsupportedBlocks (), std::unordered_set<std::string>({ " block1" , " block2" , " value_block1" , " value_block3" , " value_block5" , " block4" , " block5" , " block6" }));
17821798}
17831799
17841800TEST_F (CompilerTest, Procedure)
@@ -1818,3 +1834,21 @@ TEST_F(CompilerTest, Preoptimize)
18181834 EXPECT_CALL (*ctx, preoptimize ());
18191835 compiler.preoptimize ();
18201836}
1837+
1838+ TEST_F (CompilerTest, HatPredicate)
1839+ {
1840+ auto block = std::make_shared<Block>(" " , " " );
1841+ block->setCompileFunction ([](Compiler *compiler) -> CompilerValue * { return compiler->addConstValue (true ); });
1842+ block->setHatPredicateCompileFunction ([](Compiler *compiler) -> CompilerValue * { return compiler->addConstValue (false ); });
1843+
1844+ CompilerConstant ret1 (Compiler::StaticType::Bool, Value (true ));
1845+ CompilerConstant ret2 (Compiler::StaticType::Bool, Value (false ));
1846+
1847+ // Script
1848+ EXPECT_CALL (*m_builder, addConstValue (Value (true ))).WillOnce (Return (&ret1));
1849+ compile (m_compiler.get (), block, nullptr , false );
1850+
1851+ // Hat predicate
1852+ EXPECT_CALL (*m_builder, addConstValue (Value (false ))).WillOnce (Return (&ret2));
1853+ compile (m_compiler.get (), block, nullptr , true );
1854+ }
0 commit comments