Add test for block imports access

This commit is contained in:
Guillaume Gomez 2024-03-12 21:53:49 +01:00
parent 354e769742
commit bd0bfaa95c
4 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{% import "macro.html" as m1 %}
{% block header %}{% endblock %}

27
testing/tests/extend.rs Normal file
View File

@ -0,0 +1,27 @@
use askama::Template;
#[derive(Template)]
#[template(
source = r#"{% extends "extend_and_import.html" %}
{%- import "macro.html" as m2 -%}
{%- macro another(param) -%}
--> {{ param }}
{%- endmacro -%}
{% block header -%}
{% call m1::twice(1) %}
{% call m2::twice(2) %}
{% call another(3) %}
{%- endblock -%}
"#,
ext = "txt"
)]
struct A;
#[test]
fn test_macro_in_block_inheritance() {
assert_eq!(A.render().unwrap(), "\n\n1 1\n2 2\n--> 3");
}

View File

@ -0,0 +1,13 @@
use askama::Template;
#[derive(Template)]
#[template(source = r#"{% extends "extend_and_import.html" %}
{% let x = 12 %}
{% block header -%}
{{ x }}
{% endblock %}"#, ext = "html")]
struct A;
fn main() {
}

View File

@ -0,0 +1,7 @@
error[E0609]: no field `x` on type `&A`
--> tests/ui/block_and_vars.rs:3:10
|
3 | #[derive(Template)]
| ^^^^^^^^ unknown field
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)