@@ -198,3 +198,31 @@ TEST_F(ExtendsTest, ScopedBlocksExtends)
198198->0123456789<-)" ;
199199 EXPECT_STREQ (expectedResult.c_str (), result.c_str ());
200200}
201+
202+
203+ TEST_F (ExtendsTest, MacroUsage)
204+ {
205+ m_templateFs->AddFile (" base.j2tpl" , R"( Hello World!
206+ {% macro testMacro(str) %}{{ str | upper }}{% endmacro %}
207+ {% block regularBlock %}{% endblock regularBlock%}
208+ {% block scopedBlock scoped %}{% endblock scopedBlock%}
209+ )" );
210+ m_templateFs->AddFile (" derived.j2tpl" , R"( {% extends "base.j2tpl" %}
211+ {% block regularBlock %}->{{ testMacro('RegularMacroText') }}<-{% endblock %}
212+ Some Stuff
213+ {% block scopedBlock %}->{{ testMacro('ScopedMacroText') }}<-{% endblock %}
214+ )" );
215+
216+ auto baseTpl = m_env.LoadTemplate (" base.j2tpl" ).value ();
217+ auto tpl = m_env.LoadTemplate (" derived.j2tpl" ).value ();
218+
219+ std::string baseResult = baseTpl.RenderAsString (jinja2::ValuesMap{});
220+ std::cout << baseResult << std::endl;
221+ std::string expectedResult = " Hello World!\n " ;
222+ EXPECT_STREQ (expectedResult.c_str (), baseResult.c_str ());
223+ std::string result = tpl.RenderAsString (jinja2::ValuesMap{});
224+ std::cout << result << std::endl;
225+ expectedResult = R"( Hello World!
226+ -><-->SCOPEDMACROTEXT<-)" ;
227+ EXPECT_STREQ (expectedResult.c_str (), result.c_str ());
228+ }
0 commit comments