Skip to content

Commit

Permalink
Add regression test for issue 91
Browse files Browse the repository at this point in the history
Currently fails with:

    error: `"1_u32"` is not a valid identifier
      --> tests/test_expr.rs:56:49
       |
    56 |                         [<vec_ $bit>].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
  • Loading branch information
dtolnay committed Dec 12, 2022
1 parent 81cdb4f commit 5814fa7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_repeat() {
}

#[test]
fn test_literals() {
fn test_literal_to_identifier() {
const CONST0: &str = "const0";

let pasted = paste!([<CONST 0>]);
Expand All @@ -45,6 +45,25 @@ fn test_literals() {
assert_eq!(pasted, CONST0);
}

#[test]
fn test_literal_suffix() {
macro_rules! vec_insert {
($bit:tt) => {
paste! {
fn [<vector_insert_ $bit _bit>](insert_size: usize) {
let mut [<vec_ $bit>] = Vec::new();
for _ in 0..insert_size {
[<vec_ $bit>].insert(0, [<1_u $bit>]);
}
}
}
};
}

vec_insert!(32);
vector_insert_32_bit(2);
}

#[test]
fn test_underscore() {
paste! {
Expand Down

0 comments on commit 5814fa7

Please sign in to comment.