aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'askama_parser/src/tests.rs')
-rw-r--r--askama_parser/src/tests.rs83
1 files changed, 83 insertions, 0 deletions
diff --git a/askama_parser/src/tests.rs b/askama_parser/src/tests.rs
index 2beeb38..61aa279 100644
--- a/askama_parser/src/tests.rs
+++ b/askama_parser/src/tests.rs
@@ -761,3 +761,86 @@ fn test_missing_space_after_kw() {
"unable to parse template:\n\n\"{%leta=b%}\""
));
}
+
+#[test]
+fn test_parse_array() {
+ let syntax = Syntax::default();
+ assert_eq!(
+ Ast::from_str("{{ [] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(Ws(None, None), Expr::Array(vec![]))],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [ 1] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1 ] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1,2] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1"), Expr::NumLit("2")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1 ,2] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1"), Expr::NumLit("2")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1, 2] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1"), Expr::NumLit("2")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [1,2 ] }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Array(vec![Expr::NumLit("1"), Expr::NumLit("2")])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ []|foo }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Filter("foo", vec![Expr::Array(vec![])])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ []| foo }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::Filter("foo", vec![Expr::Array(vec![])])
+ )],
+ );
+ assert_eq!(
+ Ast::from_str("{{ [] |foo }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Expr::BinOp(
+ "|",
+ Box::new(Expr::Array(vec![])),
+ Box::new(Expr::Var("foo"))
+ ),
+ )],
+ );
+}