diff --git a/testing/tests/macro.rs b/testing/tests/macro.rs index faada370c..4a288350b 100644 --- a/testing/tests/macro.rs +++ b/testing/tests/macro.rs @@ -95,3 +95,33 @@ fn test_macro_self_arg() { let t = MacroSelfArgTemplate { s: "foo" }; assert_eq!(t.render().unwrap(), "foo"); } + +#[derive(Template)] +#[template( + source = "{%- macro thrice(param1, param2) -%} +{{ param1 }} {{ param2 }} +{% endmacro -%} + +{%- call thrice(param1=2, param2=3) -%} +{%- call thrice(param2=3, param1=2) -%} +{%- call thrice(param2=3, 2) -%} +{%- call thrice(3, param1=2) -%} +", + ext = "html" +)] +struct MacroNamedArg; + +#[test] +// We check that it's always the correct values passed to the +// expected argument. +fn test_named_argument() { + assert_eq!( + MacroNamedArg.render().unwrap(), + "\ +2 3 +2 3 +2 3 +2 3 +" + ); +} diff --git a/testing/tests/ui/macro_named_argument.rs b/testing/tests/ui/macro_named_argument.rs new file mode 100644 index 000000000..32af36841 --- /dev/null +++ b/testing/tests/ui/macro_named_argument.rs @@ -0,0 +1,20 @@ +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; + +fn main() { +} diff --git a/testing/tests/ui/macro_named_argument.stderr b/testing/tests/ui/macro_named_argument.stderr new file mode 100644 index 000000000..0b6d555d9 --- /dev/null +++ b/testing/tests/ui/macro_named_argument.stderr @@ -0,0 +1,17 @@ +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)