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) --- testing/templates/rust-macros-full-path.html | 1 + testing/tests/rust_macro.rs | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 testing/templates/rust-macros-full-path.html (limited to 'testing') diff --git a/testing/templates/rust-macros-full-path.html b/testing/templates/rust-macros-full-path.html new file mode 100644 index 0000000..f32dc53 --- /dev/null +++ b/testing/templates/rust-macros-full-path.html @@ -0,0 +1 @@ +Hello, {{ foo::hello2!() }}! diff --git a/testing/tests/rust_macro.rs b/testing/tests/rust_macro.rs index 2efe8be..1ee37e3 100644 --- a/testing/tests/rust_macro.rs +++ b/testing/tests/rust_macro.rs @@ -11,11 +11,31 @@ macro_rules! hello { struct RustMacrosTemplate {} #[test] -fn main() { +fn macro_basic() { let template = RustMacrosTemplate {}; assert_eq!("Hello, world!", template.render().unwrap()); } +mod foo { + macro_rules! hello2 { + () => { + "world" + }; + } + + pub(crate) use hello2; +} + +#[derive(Template)] +#[template(path = "rust-macros-full-path.html")] +struct RustMacrosFullPathTemplate {} + +#[test] +fn macro_full_path() { + let template = RustMacrosFullPathTemplate {}; + assert_eq!("Hello, world!", template.render().unwrap()); +} + macro_rules! call_a_or_b_on_tail { ((a: $a:expr, b: $b:expr, c: $c:expr), call a: $($tail:expr),*) => { ($a)($($tail),*) @@ -47,7 +67,7 @@ fn day(_: u16, _: &str, d: u8) -> u8 { struct RustMacrosArgTemplate {} #[test] -fn args() { +fn macro_with_args() { let template = RustMacrosArgTemplate {}; assert_eq!("2021\nJuly\n2", template.render().unwrap()); } -- cgit