Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 73d3020

Browse files
Kijewskidjc
authored andcommitted
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.
1 parent 7a5bfeb commit 73d3020

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{{ call_a_or_b_on_tail!((a: compute_len, b: zero), call b: only the terminal rules care.) }}
2-
{{ call_a_or_b_on_tail!((a: compute_len, b: zero), call a: some ninety one!) }}
3-
{{ call_a_or_b_on_tail!((a: compute_len, b: zero), call a: some ninety "(\"()"nine!) }}
1+
{{ call_a_or_b_on_tail!((a: year, b: month, c: day), call a: 2021, "July", (0+2)) }}
2+
{{ call_a_or_b_on_tail!((a: year, b: month, c: day), call b: 2021, "July", (0+2)) }}
3+
{{ call_a_or_b_on_tail!((a: year, b: day, c: month), call b: 2021, "July", (0+2)) }}

testing/tests/rust_macro.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,29 @@ fn main() {
1717
}
1818

1919
macro_rules! call_a_or_b_on_tail {
20-
((a: $a:expr, b: $b:expr), call a: $($tail:tt)*) => {
21-
$a(stringify!($($tail)*))
20+
((a: $a:expr, b: $b:expr, c: $c:expr), call a: $($tail:expr),*) => {
21+
($a)($($tail),*)
2222
};
2323

24-
((a: $a:expr, b: $b:expr), call b: $($tail:tt)*) => {
25-
$b(stringify!($($tail)*))
24+
((a: $a:expr, b: $b:expr, c: $c:expr), call b: $($tail:expr),*) => {
25+
($b)($($tail),*)
2626
};
2727

28-
($ab:tt, $_skip:tt $($tail:tt)*) => {
29-
call_a_or_b_on_tail!($ab, $($tail)*)
28+
((a: $a:expr, b: $b:expr, c: $c:expr), call c: $($tail:expr),*) => {
29+
($c)($($tail),*)
3030
};
3131
}
3232

33-
fn compute_len(s: &str) -> usize {
34-
s.len()
33+
fn year(y: u16, _: &str, _: u8) -> u16 {
34+
y
3535
}
3636

37-
fn zero(_s: &str) -> usize {
38-
0
37+
fn month(_: u16, m: &str, _: u8) -> &str {
38+
m
39+
}
40+
41+
fn day(_: u16, _: &str, d: u8) -> u8 {
42+
d
3943
}
4044

4145
#[derive(Template)]
@@ -45,5 +49,5 @@ struct RustMacrosArgTemplate {}
4549
#[test]
4650
fn args() {
4751
let template = RustMacrosArgTemplate {};
48-
assert_eq!("0\n17\n25", template.render().unwrap());
52+
assert_eq!("2021\nJuly\n2", template.render().unwrap());
4953
}

0 commit comments

Comments
 (0)