From ac8de6260e34c7dc7f7f2228e832d1860a31707d Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Mon, 24 Jul 2023 05:39:14 -0400 Subject: Fix Rust macro invocations not accepting a path (#837) --- askama_derive/src/parser/tests.rs | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'askama_derive/src/parser/tests.rs') diff --git a/askama_derive/src/parser/tests.rs b/askama_derive/src/parser/tests.rs index 91bb09b..801e787 100644 --- a/askama_derive/src/parser/tests.rs +++ b/askama_derive/src/parser/tests.rs @@ -221,6 +221,51 @@ fn test_parse_root_path() { ); } +#[test] +fn test_rust_macro() { + let syntax = Syntax::default(); + assert_eq!( + super::parse("{{ vec!(1, 2, 3) }}", &syntax).unwrap(), + vec![Node::Expr( + Ws(None, None), + Expr::RustMacro(vec!["vec"], "1, 2, 3",), + )], + ); + assert_eq!( + super::parse("{{ alloc::vec!(1, 2, 3) }}", &syntax).unwrap(), + vec![Node::Expr( + Ws(None, None), + Expr::RustMacro(vec!["alloc", "vec"], "1, 2, 3",), + )], + ); + assert_eq!( + super::parse("{{a!()}}", &syntax).unwrap(), + [Node::Expr(Ws(None, None), Expr::RustMacro(vec!["a"], ""))], + ); + assert_eq!( + super::parse("{{a !()}}", &syntax).unwrap(), + [Node::Expr(Ws(None, None), Expr::RustMacro(vec!["a"], ""))], + ); + assert_eq!( + super::parse("{{a! ()}}", &syntax).unwrap(), + [Node::Expr(Ws(None, None), Expr::RustMacro(vec!["a"], ""))], + ); + assert_eq!( + super::parse("{{a ! ()}}", &syntax).unwrap(), + [Node::Expr(Ws(None, None), Expr::RustMacro(vec!["a"], ""))], + ); + assert_eq!( + super::parse("{{A!()}}", &syntax).unwrap(), + [Node::Expr(Ws(None, None), Expr::RustMacro(vec!["A"], ""),)], + ); + assert_eq!( + &*super::parse("{{a.b.c!( hello )}}", &syntax) + .unwrap_err() + .msg, + "problems parsing template source at row 1, column 7 near:\n\"!( hello )}}\"", + ); +} + #[test] fn change_delimiters_parse_filter() { let syntax = Syntax { -- cgit