From 39e08325c0e0fba75384579427d1c6f7eca8fbc9 Mon Sep 17 00:00:00 2001 From: Juan Aguilar Santillana Date: Wed, 12 Dec 2018 22:30:57 +0100 Subject: fix rust macro arguments --- testing/tests/rust_macro.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'testing/tests') diff --git a/testing/tests/rust_macro.rs b/testing/tests/rust_macro.rs index 8a114f9..b92bbeb 100644 --- a/testing/tests/rust_macro.rs +++ b/testing/tests/rust_macro.rs @@ -15,3 +15,35 @@ fn main() { let template = RustMacrosTemplate {}; assert_eq!("Hello, world!", template.render().unwrap()); } + +macro_rules! call_a_or_b_on_tail { + ((a: $a:expr, b: $b:expr), call a: $($tail:tt)*) => { + $a(stringify!($($tail)*)) + }; + + ((a: $a:expr, b: $b:expr), call b: $($tail:tt)*) => { + $b(stringify!($($tail)*)) + }; + + ($ab:tt, $_skip:tt $($tail:tt)*) => { + call_a_or_b_on_tail!($ab, $($tail)*) + }; +} + +fn compute_len(s: &str) -> usize { + s.len() +} + +fn zero(_s: &str) -> usize { + 0 +} + +#[derive(Template)] +#[template(path = "rust-macro-args.html")] +struct RustMacrosArgTemplate {} + +#[test] +fn args() { + let template = RustMacrosArgTemplate {}; + assert_eq!("0\n91\n99", template.render().unwrap()); +} -- cgit