Add unit-test for #507

This commit is contained in:
Markus Ebner 2025-07-03 10:39:44 +02:00
parent 89c4488b66
commit 19c685b51a
No known key found for this signature in database
GPG Key ID: 2F4B02774683BA74
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{%- macro outer() -%}
<div>{{caller()}}</div>
{%- endmacro -%}
{%- macro inner() -%}
content
{%- endmacro -%}
{%- macro intermediate() -%}
intermediate
{%- call inner() -%}{%- endcall -%}
{%- endmacro -%}

View File

@ -91,6 +91,24 @@ fn test_include_in_macro_block() {
assert_eq!(x.render().unwrap(), "foo.html");
}
#[test]
fn test_macro_caller_context_is_declaration_site() {
#[derive(Template)]
#[template(
ext = "html",
source = r#"
{%- import "macro-with-caller.html" as parentscope -%}
{%- call parentscope::outer() -%}
{%- call parentscope::intermediate() -%}{%- endcall -%}
{%- endcall -%}
"#
)]
struct CallsiteContextIsDeclarationSiteTemplate {}
let t = CallsiteContextIsDeclarationSiteTemplate {};
assert_eq!(t.render().unwrap(), "<div>intermediatecontent</div>");
}
#[test]
fn str_cmp() {
#[derive(Template)]