diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2021-07-17 13:40:49 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-07-30 11:45:56 +0200 |
commit | 268d8250fb0a9cdcbbd760bdf39424ed02fd1920 (patch) | |
tree | 02a31fa920a29cff2420e597158637619cf7606c /testing/tests/matches.rs | |
parent | 1622df7aeecb71fca2da630330513b26cefef16b (diff) | |
download | askama-268d8250fb0a9cdcbbd760bdf39424ed02fd1920.tar.gz askama-268d8250fb0a9cdcbbd760bdf39424ed02fd1920.tar.bz2 askama-268d8250fb0a9cdcbbd760bdf39424ed02fd1920.zip |
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.
Diffstat (limited to 'testing/tests/matches.rs')
-rw-r--r-- | testing/tests/matches.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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"); +} |