1 use paste::paste;
2 
3 #[test]
test_paste_doc()4 fn test_paste_doc() {
5     macro_rules! m {
6         ($ret:ident) => {
7             paste! {
8                 #[doc = "Create a new [`" $ret "`] object."]
9                 fn new() -> $ret { todo!() }
10             }
11         };
12     }
13 
14     struct Paste;
15     m!(Paste);
16 
17     let _ = new;
18 }
19 
20 macro_rules! get_doc {
21     (#[doc = $literal:tt]) => {
22         $literal
23     };
24 }
25 
26 #[test]
test_escaping()27 fn test_escaping() {
28     let doc = paste! {
29         get_doc!(#[doc = "s\"" r#"r#""#])
30     };
31 
32     let expected = "s\"r#\"";
33     assert_eq!(doc, expected);
34 }
35 
36 #[test]
test_literals()37 fn test_literals() {
38     let doc = paste! {
39         get_doc!(#[doc = "int=" 0x1 " bool=" true " float=" 0.01])
40     };
41 
42     let expected = "int=0x1 bool=true float=0.01";
43     assert_eq!(doc, expected);
44 }
45 
46 #[test]
test_case()47 fn test_case() {
48     let doc = paste! {
49         get_doc!(#[doc = "HTTP " get:upper "!"])
50     };
51 
52     let expected = "HTTP GET!";
53     assert_eq!(doc, expected);
54 }
55 
56 // https://github.com/dtolnay/paste/issues/63
57 #[test]
test_stringify()58 fn test_stringify() {
59     macro_rules! create {
60         ($doc:expr) => {
61             paste! {
62                 #[doc = $doc]
63                 pub struct Struct;
64             }
65         };
66     }
67 
68     macro_rules! forward {
69         ($name:ident) => {
70             create!(stringify!($name));
71         };
72     }
73 
74     forward!(documentation);
75 
76     let _ = Struct;
77 }
78