Debian Codegraph @

.cargo/vendor/paste/tests/test_doc.rs

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