mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Add test specifically for named blocks, and named macros
This commit is contained in:
parent
5ee2dfbe6b
commit
a7f5186bf4
9
testing/templates/named-end.html
Normal file
9
testing/templates/named-end.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{# Testing named "endmacro" #}
|
||||||
|
{% macro foo(b) -%}
|
||||||
|
{% if b %}t{% else %}f{% endif -%}
|
||||||
|
{% endmacro foo -%}
|
||||||
|
{# Testing named endblock declaration #}
|
||||||
|
{% block what %}{% endblock what %}
|
||||||
|
{# Testing named endblock call #}
|
||||||
|
{% block foo %}tadam{% endblock foo %}
|
@ -340,3 +340,15 @@ fn test_let_block() {
|
|||||||
let t = LetChild {};
|
let t = LetChild {};
|
||||||
assert_eq!(t.render().unwrap(), "1");
|
assert_eq!(t.render().unwrap(), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "named-end.html")]
|
||||||
|
struct NamedBlocks<'a> {
|
||||||
|
title: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_named_end() {
|
||||||
|
let n = NamedBlocks { title: "title" };
|
||||||
|
assert_eq!(n.render().unwrap(), "title\n\ntadam\nCopyright 2017");
|
||||||
|
}
|
||||||
|
8
testing/tests/ui/name_mismatch_endblock.rs
Normal file
8
testing/tests/ui/name_mismatch_endblock.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{% block foo %}{% endblock not_foo %}", ext = "html")]
|
||||||
|
struct NameMismatchEndBlock;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
8
testing/tests/ui/name_mismatch_endblock.stderr
Normal file
8
testing/tests/ui/name_mismatch_endblock.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
error: problems parsing template source at row 1, column 27 near:
|
||||||
|
"not_foo %}"
|
||||||
|
--> tests/ui/name_mismatch_endblock.rs:3:10
|
||||||
|
|
|
||||||
|
3 | #[derive(Template)]
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
8
testing/tests/ui/name_mismatch_endmacro.rs
Normal file
8
testing/tests/ui/name_mismatch_endmacro.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{% macro foo(arg) %} {{arg}} {% endmacro not_foo %}", ext = "html")]
|
||||||
|
struct NameMismatchEndMacro;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
8
testing/tests/ui/name_mismatch_endmacro.stderr
Normal file
8
testing/tests/ui/name_mismatch_endmacro.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
error: problems parsing template source at row 1, column 41 near:
|
||||||
|
"not_foo %}"
|
||||||
|
--> tests/ui/name_mismatch_endmacro.rs:3:10
|
||||||
|
|
|
||||||
|
3 | #[derive(Template)]
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
= 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