From 268d8250fb0a9cdcbbd760bdf39424ed02fd1920 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Sat, 17 Jul 2021 13:40:49 +0200 Subject: Use "target()" to parse "when" block `target()` as used in parsing "let" and "if let" implements parsing nested tuples and structs. But it does not implement parsing literals. The functions `match_variant()` and `with_parameters()` as used in parsing "when" blocks do not implement parsing nested structs, but it implements parsing literals. This PR combines `match_variant()` and `with_parameters()` into `target()`, so that all `{%when%}` support nested structs, too. --- testing/tests/vars.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'testing/tests/vars.rs') diff --git a/testing/tests/vars.rs b/testing/tests/vars.rs index 75d10e5..5447351 100644 --- a/testing/tests/vars.rs +++ b/testing/tests/vars.rs @@ -105,3 +105,29 @@ fn test_destruct_tuple() { }; assert_eq!(t.render().unwrap(), "wxyz\nwz\nw"); } + +#[derive(Template)] +#[template( + source = "{% let x = 1 %}{% for x in x..=x %}{{ x }}{% endfor %}", + ext = "txt" +)] +struct DeclRange; + +#[test] +fn test_decl_range() { + let t = DeclRange; + assert_eq!(t.render().unwrap(), "1"); +} + +#[derive(Template)] +#[template( + source = "{% let x %}{% let x = 1 %}{% for x in x..=x %}{{ x }}{% endfor %}", + ext = "txt" +)] +struct DeclAssignRange; + +#[test] +fn test_decl_assign_range() { + let t = DeclAssignRange; + assert_eq!(t.render().unwrap(), "1"); +} -- cgit