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