mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Add test for block imports access
This commit is contained in:
parent
354e769742
commit
bd0bfaa95c
3
testing/templates/extend_and_import.html
Normal file
3
testing/templates/extend_and_import.html
Normal file
@ -0,0 +1,3 @@
|
||||
{% import "macro.html" as m1 %}
|
||||
|
||||
{% block header %}{% endblock %}
|
27
testing/tests/extend.rs
Normal file
27
testing/tests/extend.rs
Normal 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");
|
||||
}
|
13
testing/tests/ui/block_and_vars.rs
Normal file
13
testing/tests/ui/block_and_vars.rs
Normal 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() {
|
||||
}
|
7
testing/tests/ui/block_and_vars.stderr
Normal file
7
testing/tests/ui/block_and_vars.stderr
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user