Skip to content

Commit

Permalink
Improved filter parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
vallentin authored and djc committed Jan 5, 2021
1 parent a363387 commit e84e958
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion askama_shared/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e84e958

Please sign in to comment.