diff options
Diffstat (limited to '')
-rw-r--r-- | testing/templates/match-option-result-option.html | 10 | ||||
-rw-r--r-- | testing/tests/matches.rs | 24 | ||||
-rw-r--r-- | testing/tests/ui/lit_on_assignment_lhs.rs | 11 | ||||
-rw-r--r-- | testing/tests/ui/lit_on_assignment_lhs.stderr | 7 | ||||
-rw-r--r-- | testing/tests/vars.rs | 26 |
5 files changed, 78 insertions, 0 deletions
diff --git a/testing/templates/match-option-result-option.html b/testing/templates/match-option-result-option.html new file mode 100644 index 0000000..25396b6 --- /dev/null +++ b/testing/templates/match-option-result-option.html @@ -0,0 +1,10 @@ +{%- match foo -%} + {%- when None -%} + nothing + {%- when Some(Err(err)) -%} + err={{err}} + {%- when Some(Ok(None)) -%} + num=absent + {%- when Some(Ok(Some(num))) -%} + num={{num}} +{%- endmatch -%} diff --git a/testing/tests/matches.rs b/testing/tests/matches.rs index 380a69c..c328e39 100644 --- a/testing/tests/matches.rs +++ b/testing/tests/matches.rs @@ -130,3 +130,27 @@ fn test_match_without_with_keyword() { let s = MatchWithoutWithKeyword { foo: None }; assert_eq!(s.render().unwrap(), ""); } + +#[derive(Template)] +#[template(path = "match-option-result-option.html")] +struct MatchOptionResultOption { + foo: Option<Result<Option<usize>, &'static str>>, +} + +#[test] +fn test_match_option_result_option() { + let s = MatchOptionResultOption { foo: None }; + assert_eq!(s.render().unwrap(), "nothing"); + let s = MatchOptionResultOption { + foo: Some(Err("fail")), + }; + assert_eq!(s.render().unwrap(), "err=fail"); + let s = MatchOptionResultOption { + foo: Some(Ok(None)), + }; + assert_eq!(s.render().unwrap(), "num=absent"); + let s = MatchOptionResultOption { + foo: Some(Ok(Some(4711))), + }; + assert_eq!(s.render().unwrap(), "num=4711"); +} diff --git a/testing/tests/ui/lit_on_assignment_lhs.rs b/testing/tests/ui/lit_on_assignment_lhs.rs new file mode 100644 index 0000000..1793770 --- /dev/null +++ b/testing/tests/ui/lit_on_assignment_lhs.rs @@ -0,0 +1,11 @@ +use askama::Template; + +#[derive(Template)] +#[template( + source = "{%let 7=x%}", + ext = "txt" +)] +struct MyTemplate; + +fn main() { +} diff --git a/testing/tests/ui/lit_on_assignment_lhs.stderr b/testing/tests/ui/lit_on_assignment_lhs.stderr new file mode 100644 index 0000000..fa488cb --- /dev/null +++ b/testing/tests/ui/lit_on_assignment_lhs.stderr @@ -0,0 +1,7 @@ +error: proc-macro derive panicked + --> $DIR/lit_on_assignment_lhs.rs:3:10 + | +3 | #[derive(Template)] + | ^^^^^^^^ + | + = help: message: Cannot have literals on the left-hand-side of an assignment. 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"); +} |