From 20f34be742b27f18d944d60dcb3e04b822c6d9ef Mon Sep 17 00:00:00 2001 From: vallentin Date: Wed, 23 Dec 2020 15:11:53 +0100 Subject: Added let shadow test --- testing/templates/let-shadow.html | 22 ++++++++++++++++++++++ testing/tests/vars.rs | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 testing/templates/let-shadow.html (limited to 'testing') diff --git a/testing/templates/let-shadow.html b/testing/templates/let-shadow.html new file mode 100644 index 0000000..938c5bf --- /dev/null +++ b/testing/templates/let-shadow.html @@ -0,0 +1,22 @@ +{%- let a = 1 -%} +{%- let b -%} + +{%- if cond -%} + {%- let b = 22 -%} + {{ b }}- + + {%- let b = 33 -%} + {{ a }}-{{ b }}- +{%- else -%} + {%- let b = 222 -%} + {{ b }}- + + {%- let b = 333 -%} + {{ a }}-{{ b }}- + + {%- let (a, b) = Self::tuple() -%} + {{ a }}-{{ b }}- +{%- endif -%} + +{%- let a = 11 -%} +{{ a }}-{{ b }} diff --git a/testing/tests/vars.rs b/testing/tests/vars.rs index d1c41f9..d70a084 100644 --- a/testing/tests/vars.rs +++ b/testing/tests/vars.rs @@ -46,6 +46,27 @@ fn test_let_decl() { assert_eq!(t.render().unwrap(), "bar"); } +#[derive(Template)] +#[template(path = "let-shadow.html")] +struct LetShadowTemplate { + cond: bool, +} + +impl LetShadowTemplate { + fn tuple() -> (i32, i32) { + (4, 5) + } +} + +#[test] +fn test_let_shadow() { + let t = LetShadowTemplate { cond: true }; + assert_eq!(t.render().unwrap(), "22-1-33-11-22"); + + let t = LetShadowTemplate { cond: false }; + assert_eq!(t.render().unwrap(), "222-1-333-4-5-11-222"); +} + #[derive(Template)] #[template(source = "{% for v in self.0 %}{{ v }}{% endfor %}", ext = "txt")] struct SelfIterTemplate(Vec); -- cgit