diff options
author | vallentin <mail@vallentin.dev> | 2021-01-05 15:40:47 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-01-05 16:15:16 +0100 |
commit | e84e958a73d623a38b063915a90ba6371326a350 (patch) | |
tree | 0fed1823d774221effae7fbc1c80be3627134c94 /askama_shared | |
parent | a3633879e302f5fd9034a17b9520fdf8c1b18ff9 (diff) | |
download | askama-e84e958a73d623a38b063915a90ba6371326a350.tar.gz askama-e84e958a73d623a38b063915a90ba6371326a350.tar.bz2 askama-e84e958a73d623a38b063915a90ba6371326a350.zip |
Improved filter parsing test
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/parser.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 58f29f6..e13a54a 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -1126,7 +1126,41 @@ mod tests { #[test] fn test_parse_filter() { - super::parse("{{ strvar|e }}", &Syntax::default()).unwrap(); + use Expr::*; + let syntax = Syntax::default(); + assert_eq!( + super::parse("{{ strvar|e }}", &syntax).unwrap(), + vec![Node::Expr( + WS(false, false), + Filter("e", vec![Var("strvar")]), + )], + ); + assert_eq!( + super::parse("{{ 2|abs }}", &syntax).unwrap(), + vec![Node::Expr( + WS(false, false), + Filter("abs", vec![NumLit("2")]), + )], + ); + assert_eq!( + super::parse("{{ -2|abs }}", &syntax).unwrap(), + vec![Node::Expr( + WS(false, false), + Filter("abs", vec![Unary("-", NumLit("2").into())]), + )], + ); + assert_eq!( + super::parse("{{ (1 - 2)|abs }}", &syntax).unwrap(), + vec![Node::Expr( + WS(false, false), + Filter( + "abs", + vec![Group( + BinOp("-", NumLit("1").into(), NumLit("2").into()).into() + )] + ), + )], + ); } #[test] |