Add UI tests for top level nodes

This commit is contained in:
Guillaume Gomez 2024-07-02 21:35:53 +02:00
parent 79e7331ccc
commit 27e12f083b
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,29 @@
use rinja::Template;
#[derive(Template)]
#[template(source = r#"
{% block bla %}
{% extends "bla.txt" %}
{% endblock %}
"#, ext = "txt")]
struct MyTemplate1;
#[derive(Template)]
#[template(source = r#"
{% block bla %}
{% macro bla() %}
{% endmacro %}
{% endblock %}
"#, ext = "txt")]
struct MyTemplate2;
#[derive(Template)]
#[template(source = r#"
{% block bla %}
{% import "bla.txt" as blue %}
{% endblock %}
"#, ext = "txt")]
struct MyTemplate3;
fn main() {
}

View File

@ -0,0 +1,29 @@
error: extends blocks are not allowed below top level
--> MyTemplate1.txt:3:2
" extends \"bla.txt\" %}\n{% endblock %}\n"
--> tests/ui/blocks_below_top_level.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)
error: macro blocks are not allowed below top level
--> MyTemplate2.txt:3:2
" macro bla() %}\n{% endmacro %}\n{% endblo"...
--> tests/ui/blocks_below_top_level.rs:11:10
|
11 | #[derive(Template)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
error: import blocks are not allowed below top level
--> MyTemplate3.txt:3:2
" import \"bla.txt\" as blue %}\n{% endblock"...
--> tests/ui/blocks_below_top_level.rs:20:10
|
20 | #[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,10 @@
use rinja::Template;
#[derive(Template)]
#[template(source = r#"
{% extends "let.html" %}
{% extends "foo.html" %}
"#, ext = "txt")]
struct MyTemplate4;
fn main() {}

View File

@ -0,0 +1,9 @@
error: multiple extend blocks found
--> MyTemplate4.txt:3:2
" extends \"foo.html\" %}\n"
--> tests/ui/multiple_extends.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)