From a7f5186bf49ef20010c2eae7717b3a738a3b548e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Oct 2023 13:32:37 +0200 Subject: Add test specifically for named blocks, and named macros --- testing/templates/named-end.html | 9 +++++++++ testing/tests/inheritance.rs | 12 ++++++++++++ testing/tests/ui/name_mismatch_endblock.rs | 8 ++++++++ testing/tests/ui/name_mismatch_endblock.stderr | 8 ++++++++ testing/tests/ui/name_mismatch_endmacro.rs | 8 ++++++++ testing/tests/ui/name_mismatch_endmacro.stderr | 8 ++++++++ 6 files changed, 53 insertions(+) create mode 100644 testing/templates/named-end.html create mode 100644 testing/tests/ui/name_mismatch_endblock.rs create mode 100644 testing/tests/ui/name_mismatch_endblock.stderr create mode 100644 testing/tests/ui/name_mismatch_endmacro.rs create mode 100644 testing/tests/ui/name_mismatch_endmacro.stderr (limited to 'testing') diff --git a/testing/templates/named-end.html b/testing/templates/named-end.html new file mode 100644 index 0000000..35eb0bb --- /dev/null +++ b/testing/templates/named-end.html @@ -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 %} diff --git a/testing/tests/inheritance.rs b/testing/tests/inheritance.rs index 5d8aefb..906be04 100644 --- a/testing/tests/inheritance.rs +++ b/testing/tests/inheritance.rs @@ -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"); +} diff --git a/testing/tests/ui/name_mismatch_endblock.rs b/testing/tests/ui/name_mismatch_endblock.rs new file mode 100644 index 0000000..9fbfbe4 --- /dev/null +++ b/testing/tests/ui/name_mismatch_endblock.rs @@ -0,0 +1,8 @@ +use askama::Template; + +#[derive(Template)] +#[template(source = "{% block foo %}{% endblock not_foo %}", ext = "html")] +struct NameMismatchEndBlock; + +fn main() { +} diff --git a/testing/tests/ui/name_mismatch_endblock.stderr b/testing/tests/ui/name_mismatch_endblock.stderr new file mode 100644 index 0000000..2cd7aaf --- /dev/null +++ b/testing/tests/ui/name_mismatch_endblock.stderr @@ -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) diff --git a/testing/tests/ui/name_mismatch_endmacro.rs b/testing/tests/ui/name_mismatch_endmacro.rs new file mode 100644 index 0000000..10ea31f --- /dev/null +++ b/testing/tests/ui/name_mismatch_endmacro.rs @@ -0,0 +1,8 @@ +use askama::Template; + +#[derive(Template)] +#[template(source = "{% macro foo(arg) %} {{arg}} {% endmacro not_foo %}", ext = "html")] +struct NameMismatchEndMacro; + +fn main() { +} diff --git a/testing/tests/ui/name_mismatch_endmacro.stderr b/testing/tests/ui/name_mismatch_endmacro.stderr new file mode 100644 index 0000000..ef389a2 --- /dev/null +++ b/testing/tests/ui/name_mismatch_endmacro.stderr @@ -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) -- cgit