Debian Codegraph @

third_party/rust/paste/tests/test_attr.rs

raw
1 use paste::paste;
2 use paste_test_suite::paste_test;
3
4 #[test]
5 fn test_attr() {
6 paste! {
7 #[paste_test(k = "val" "ue")]
8 struct A;
9
10 #[paste_test_suite::paste_test(k = "val" "ue")]
11 struct B;
12
13 #[::paste_test_suite::paste_test(k = "val" "ue")]
14 struct C;
15
16 #[paste_test(k = "va" [<l u>] e)]
17 struct D;
18 }
19
20 let _ = A;
21 let _ = B;
22 let _ = C;
23 let _ = D;
24 }
25
26 #[test]
27 fn test_paste_cfg() {
28 macro_rules! m {
29 ($ret:ident, $width:expr) => {
30 paste! {
31 #[cfg(any(feature = "protocol_feature_" $ret:snake, target_pointer_width = "" $width))]
32 fn new() -> $ret { todo!() }
33 }
34 };
35 }
36
37 struct Paste;
38
39 #[cfg(target_pointer_width = "64")]
40 m!(Paste, 64);
41 #[cfg(target_pointer_width = "32")]
42 m!(Paste, 32);
43
44 let _ = new;
45 }
46
47 #[test]
48 fn test_path_in_attr() {
49 macro_rules! m {
50 (#[x = $x:ty]) => {
51 stringify!($x)
52 };
53 }
54
55 let ty = paste! {
56 m!(#[x = foo::Bar])
57 };
58
59 assert_eq!("foo::Bar", ty);
60 }