mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 14:31:36 +00:00
Allow trailing comma in macro definition and call
This commit is contained in:
parent
7f30a657f6
commit
e4b8ca3c44
@ -119,7 +119,7 @@ impl<'a> Expr<'a> {
|
||||
}
|
||||
}),
|
||||
),
|
||||
char(')'),
|
||||
tuple((opt(ws(char(','))), char(')'))),
|
||||
)),
|
||||
)(i)
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ impl<'a> Macro<'a> {
|
||||
delimited(
|
||||
ws(char('(')),
|
||||
separated_list0(char(','), ws(identifier)),
|
||||
ws(char(')')),
|
||||
tuple((opt(ws(char(','))), char(')'))),
|
||||
)(i)
|
||||
}
|
||||
|
||||
|
@ -140,3 +140,33 @@ struct OnlyNamedArgument;
|
||||
fn test_only_named_argument() {
|
||||
assert_eq!(OnlyNamedArgument.render().unwrap(), "hi");
|
||||
}
|
||||
|
||||
// Check for trailing commas.
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
source = r#"{% macro button(label , ) %}
|
||||
{{- label -}}
|
||||
{% endmacro %}
|
||||
{%- macro button2(label ,) %}
|
||||
{% endmacro %}
|
||||
{%- macro button3(label,) %}
|
||||
{% endmacro %}
|
||||
{%- macro button4(label, ) %}
|
||||
{% endmacro %}
|
||||
{%- macro button5(label ) %}
|
||||
{% endmacro %}
|
||||
|
||||
{%- call button(label="hi" , ) -%}
|
||||
{%- call button(label="hi" ,) -%}
|
||||
{%- call button(label="hi",) -%}
|
||||
{%- call button(label="hi", ) -%}
|
||||
{%- call button(label="hi" ) -%}
|
||||
"#,
|
||||
ext = "html"
|
||||
)]
|
||||
struct TrailingComma;
|
||||
|
||||
#[test]
|
||||
fn test_trailing_comma() {
|
||||
assert_eq!(TrailingComma.render().unwrap(), "hihihihihi");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user