diff options
author | vallentin <mail@vallentin.dev> | 2021-02-22 04:15:18 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-02-22 13:50:09 +0100 |
commit | a07a1d8b7b829ca0065e3026c05eec9b64e65e49 (patch) | |
tree | b09dbcbc8ae17e7bedfb2b88e81c7b81cf53ff8a /askama_shared | |
parent | fb080df3ed384454be4f07a9bf9785194b7f5097 (diff) | |
download | askama-a07a1d8b7b829ca0065e3026c05eec9b64e65e49.tar.gz askama-a07a1d8b7b829ca0065e3026c05eec9b64e65e49.tar.bz2 askama-a07a1d8b7b829ca0065e3026c05eec9b64e65e49.zip |
Added var and path parser tests
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/parser.rs | 73 |
1 files changed, 72 insertions, 1 deletions
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 @@ -1227,6 +1227,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!( super::parse("{{ function(\"123\", 3) }}", &Syntax::default()).unwrap(), @@ -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( |