aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Juan Aguilar Santillana <mhpoin@gmail.com>2018-12-12 22:30:57 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-12-13 09:32:03 +0100
commit39e08325c0e0fba75384579427d1c6f7eca8fbc9 (patch)
tree317b3f5dc122d6c99cf301fb7de8fb88c88c3690 /testing
parent65b4f6aae7f83df02449f21d857e640911975a36 (diff)
downloadaskama-39e08325c0e0fba75384579427d1c6f7eca8fbc9.tar.gz
askama-39e08325c0e0fba75384579427d1c6f7eca8fbc9.tar.bz2
askama-39e08325c0e0fba75384579427d1c6f7eca8fbc9.zip
fix rust macro arguments
Diffstat (limited to '')
-rw-r--r--testing/templates/rust-macro-args.html26
-rw-r--r--testing/tests/rust_macro.rs32
2 files changed, 58 insertions, 0 deletions
diff --git a/testing/templates/rust-macro-args.html b/testing/templates/rust-macro-args.html
new file mode 100644
index 0000000..b009a73
--- /dev/null
+++ b/testing/templates/rust-macro-args.html
@@ -0,0 +1,26 @@
+{{
+ call_a_or_b_on_tail!(
+ (a: compute_len, b: zero),
+ the recursive part that skips over all these
+ tokens doesn't much care whether we will call a
+ or call b: only the terminal rules care.
+ )
+}}
+{{
+ call_a_or_b_on_tail!(
+ (a: compute_len, b: zero),
+ and now, to justify the existence of two paths
+ we will also call a: its input should somehow
+ be self-referential, so let's make it return
+ some ninety one!
+ )
+}}
+{{
+ call_a_or_b_on_tail!(
+ (a: compute_len, b: zero),
+ and now, to justify the existence of two paths
+ we will also call a: its input should somehow
+ be self-referential, so let's make it return
+ some ninety "(\"()"nine!
+ )
+}}
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());
+}