From a07a1d8b7b829ca0065e3026c05eec9b64e65e49 Mon Sep 17 00:00:00 2001 From: vallentin Date: Mon, 22 Feb 2021 04:15:18 +0100 Subject: Added var and path parser tests --- askama_shared/src/parser.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'askama_shared/src') diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index ef88e50..df3ee8f 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -1226,6 +1226,60 @@ mod tests { ); } + #[test] + fn test_parse_var() { + let s = Syntax::default(); + + assert_eq!( + super::parse("{{ foo }}", &s).unwrap(), + vec![Node::Expr(Ws(false, false), Expr::Var("foo"))], + ); + assert_eq!( + super::parse("{{ FOO }}", &s).unwrap(), + vec![Node::Expr(Ws(false, false), Expr::Var("FOO"))], + ); + + assert_eq!( + super::parse("{{ none }}", &s).unwrap(), + vec![Node::Expr(Ws(false, false), Expr::Var("none"))], + ); + assert_eq!( + super::parse("{{ NONE }}", &s).unwrap(), + vec![Node::Expr(Ws(false, false), Expr::Var("NONE"))], + ); + } + + #[test] + fn test_parse_path() { + let s = Syntax::default(); + + assert_eq!( + super::parse("{{ None }}", &s).unwrap(), + vec![Node::Expr(Ws(false, false), Expr::Path(vec!["None"]))], + ); + assert_eq!( + super::parse("{{ Some(123) }}", &s).unwrap(), + vec![Node::Expr( + Ws(false, false), + Expr::PathCall(vec!["Some"], vec![Expr::NumLit("123")],), + )], + ); + assert_eq!( + super::parse("{{ Ok(123) }}", &s).unwrap(), + vec![Node::Expr( + Ws(false, false), + Expr::PathCall(vec!["Ok"], vec![Expr::NumLit("123")],), + )], + ); + assert_eq!( + super::parse("{{ Err(123) }}", &s).unwrap(), + vec![Node::Expr( + Ws(false, false), + Expr::PathCall(vec!["Err"], vec![Expr::NumLit("123")],), + )], + ); + } + #[test] fn test_parse_var_call() { assert_eq!( @@ -1239,8 +1293,25 @@ mod tests { #[test] fn test_parse_path_call() { + let s = Syntax::default(); + + assert_eq!( + super::parse("{{ Option::None }}", &s).unwrap(), + vec![Node::Expr( + Ws(false, false), + Expr::Path(vec!["Option", "None"]) + )], + ); + assert_eq!( + super::parse("{{ Option::Some(123) }}", &s).unwrap(), + vec![Node::Expr( + Ws(false, false), + Expr::PathCall(vec!["Option", "Some"], vec![Expr::NumLit("123")],), + )], + ); + assert_eq!( - super::parse("{{ self::function(\"123\", 3) }}", &Syntax::default()).unwrap(), + super::parse("{{ self::function(\"123\", 3) }}", &s).unwrap(), vec![Node::Expr( Ws(false, false), Expr::PathCall( -- cgit