diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2021-07-02 09:47:15 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-07-02 16:37:11 +0200 |
commit | e9badca2573a8e6f89e14a75446e1c890ebd843f (patch) | |
tree | 43ba50419c699dadc185c506805f0402bdac62f0 /testing/tests/rust_macro.rs | |
parent | c31fe5f3fc313ca539ff1f1c92cc1337a472e809 (diff) | |
download | askama-e9badca2573a8e6f89e14a75446e1c890ebd843f.tar.gz askama-e9badca2573a8e6f89e14a75446e1c890ebd843f.tar.bz2 askama-e9badca2573a8e6f89e14a75446e1c890ebd843f.zip |
Replace rust_macro test to work on nightly
The current rust_test uses `stringify!()`. The documentation gives us
the warning:
> Note that the expanded results of the input tokens may change in the
> future. You should be careful if you rely on the output.
In the current nightly rust the result was indeed changed, so the test
not fails.
This PR replaces the test with another macro, that does not depend on
`stringify!()`.
Closes issue #504.
Diffstat (limited to '')
-rw-r--r-- | testing/tests/rust_macro.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/testing/tests/rust_macro.rs b/testing/tests/rust_macro.rs index 8d2543d..2efe8be 100644 --- a/testing/tests/rust_macro.rs +++ b/testing/tests/rust_macro.rs @@ -17,25 +17,29 @@ fn main() { } 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, c: $c:expr), call a: $($tail:expr),*) => { + ($a)($($tail),*) }; - ((a: $a:expr, b: $b:expr), call b: $($tail:tt)*) => { - $b(stringify!($($tail)*)) + ((a: $a:expr, b: $b:expr, c: $c:expr), call b: $($tail:expr),*) => { + ($b)($($tail),*) }; - ($ab:tt, $_skip:tt $($tail:tt)*) => { - call_a_or_b_on_tail!($ab, $($tail)*) + ((a: $a:expr, b: $b:expr, c: $c:expr), call c: $($tail:expr),*) => { + ($c)($($tail),*) }; } -fn compute_len(s: &str) -> usize { - s.len() +fn year(y: u16, _: &str, _: u8) -> u16 { + y } -fn zero(_s: &str) -> usize { - 0 +fn month(_: u16, m: &str, _: u8) -> &str { + m +} + +fn day(_: u16, _: &str, d: u8) -> u8 { + d } #[derive(Template)] @@ -45,5 +49,5 @@ struct RustMacrosArgTemplate {} #[test] fn args() { let template = RustMacrosArgTemplate {}; - assert_eq!("0\n17\n25", template.render().unwrap()); + assert_eq!("2021\nJuly\n2", template.render().unwrap()); } |