-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for named arguments in macro calls
- Loading branch information
1 parent
7daa1cb
commit ebfd0cd
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use askama::Template; | ||
|
||
#[derive(Template)] | ||
#[template(source = "{%- macro thrice(param1, param2) -%} | ||
{{ param1 }} {{ param2 }} | ||
{%- endmacro -%} | ||
{%- call thrice(param1=2, param3=3) -%}", ext = "html")] | ||
struct InvalidNamedArg; | ||
|
||
#[derive(Template)] | ||
#[template(source = "{%- macro thrice(param1, param2) -%} | ||
{{ param1 }} {{ param2 }} | ||
{%- endmacro -%} | ||
{%- call thrice(param1=2, param1=3) -%}", ext = "html")] | ||
struct InvalidNamedArg2; | ||
|
||
// Ensures that filters can't have named arguments. | ||
#[derive(Template)] | ||
#[template(source = "{%- macro thrice(param1, param2) -%} | ||
{{ param1 }} {{ param2 }} | ||
{%- endmacro -%} | ||
{%- call thrice(3, param1=2) | filter(param1=12) -%}", ext = "html")] | ||
struct InvalidNamedArg3; | ||
|
||
// Ensures that named arguments can only be passed last. | ||
#[derive(Template)] | ||
#[template(source = "{%- macro thrice(param1, param2) -%} | ||
{{ param1 }} {{ param2 }} | ||
{%- endmacro -%} | ||
{%- call thrice(param1=2, 3) -%}", ext = "html")] | ||
struct InvalidNamedArg4; | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error: no argument named `param3` in macro "thrice" | ||
--> tests/ui/macro_named_argument.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: named argument `param1` was passed more than once | ||
problems parsing template source at row 5, column 15 near: | ||
"(param1=2, param1=3) -%}" | ||
--> tests/ui/macro_named_argument.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: problems parsing template source at row 5, column 29 near: | ||
"| filter(param1=12) -%}" | ||
--> tests/ui/macro_named_argument.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) | ||
|
||
error: named arguments must always be passed last | ||
problems parsing template source at row 4, column 15 near: | ||
"(param1=2, 3) -%}" | ||
--> tests/ui/macro_named_argument.rs:29:10 | ||
| | ||
29 | #[derive(Template)] | ||
| ^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) |