Debian Codegraph @

third_party/rust/paste/tests/test_doc.rs

raw
1 use paste::paste;
2
3 #[test]
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]
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]
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]
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]
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 }