Add test specifically for named blocks, and named macros

This commit is contained in:
Guillaume Gomez 2023-10-23 13:32:37 +02:00 committed by Dirkjan Ochtman
parent 5ee2dfbe6b
commit a7f5186bf4
6 changed files with 53 additions and 0 deletions

View 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 %}

View File

@ -340,3 +340,15 @@ fn test_let_block() {
let t = LetChild {};
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");
}

View File

@ -0,0 +1,8 @@
use askama::Template;
#[derive(Template)]
#[template(source = "{% block foo %}{% endblock not_foo %}", ext = "html")]
struct NameMismatchEndBlock;
fn main() {
}

View 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)

View 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() {
}

View 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)