Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Add regression test for issue 7
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 26, 2020
1 parent 949f5cc commit 92e1954
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,38 @@ mod test_x86_feature_literal {

my_is_x86_feature_detected!("mmx");
}

mod test_local_setter {
// https://github.com/dtolnay/paste/issues/7

use paste::paste;

#[derive(Default)]
struct Test {
val: i32,
}

impl Test {
fn set_val(&mut self, arg: i32) {
self.val = arg;
}
}

macro_rules! setter {
($obj:expr, $field:ident, $value:expr) => {
paste! { $obj.[<set_ $field>]($value); }
};

($field:ident, $value:expr) => {{
let mut new = Test::default();
setter!(new, val, $value);
new
}};
}

#[test]
fn test_local_setter() {
let a = setter!(val, 42);
assert_eq!(a.val, 42);
}
}

0 comments on commit 92e1954

Please sign in to comment.