From 5814fa70ca9124b54ba638cf44c508ad6501acde Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 12 Dec 2022 11:10:00 -0800 Subject: [PATCH] Add regression test for issue 91 Currently fails with: error: `"1_u32"` is not a valid identifier --> tests/test_expr.rs:56:49 | 56 | [].insert(0, [<1_u $bit>]); | ^^^^^^^^^^^^ ... 63 | vec_insert!(32); | --------------- in this macro invocation | = note: this error originates in the macro `vec_insert` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find function `vector_insert_32_bit` in this scope --> tests/test_expr.rs:64:5 | 64 | vector_insert_32_bit(2); | ^^^^^^^^^^^^^^^^^^^^ not found in this scope --- tests/test_expr.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 8ad5de9..b135ff3 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -26,7 +26,7 @@ fn test_repeat() { } #[test] -fn test_literals() { +fn test_literal_to_identifier() { const CONST0: &str = "const0"; let pasted = paste!([]); @@ -45,6 +45,25 @@ fn test_literals() { assert_eq!(pasted, CONST0); } +#[test] +fn test_literal_suffix() { + macro_rules! vec_insert { + ($bit:tt) => { + paste! { + fn [](insert_size: usize) { + let mut [] = Vec::new(); + for _ in 0..insert_size { + [].insert(0, [<1_u $bit>]); + } + } + } + }; + } + + vec_insert!(32); + vector_insert_32_bit(2); +} + #[test] fn test_underscore() { paste! {