From 28e26751cef5ca5e3b0a0e6e8c8aadff92dc615b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 Nov 2023 14:40:12 +0100 Subject: Add tests for named arguments in macro calls --- testing/tests/ui/macro_named_argument.rs | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 testing/tests/ui/macro_named_argument.rs (limited to 'testing/tests/ui/macro_named_argument.rs') diff --git a/testing/tests/ui/macro_named_argument.rs b/testing/tests/ui/macro_named_argument.rs new file mode 100644 index 0000000..fe8a194 --- /dev/null +++ b/testing/tests/ui/macro_named_argument.rs @@ -0,0 +1,45 @@ +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; + +// Ensures that named arguments can't be used for arguments before them. +#[derive(Template)] +#[template(source = "{%- macro thrice(param1, param2) -%} +{{ param1 }} {{ param2 }} +{%- endmacro -%} +{%- call thrice(3, param1=2) -%}", ext = "html")] +struct InvalidNamedArg5; + +fn main() { +} -- cgit