forked from dtolnay/reflect
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_debug.rs
More file actions
89 lines (80 loc) · 2.84 KB
/
test_debug.rs
File metadata and controls
89 lines (80 loc) · 2.84 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
#![recursion_limit = "256"]
use quote::quote;
mod debug;
#[test]
fn test_debug() {
let input = quote! {
struct Point {
x: i32,
y: i32,
}
};
let expected = quote! {
impl ::std::fmt::Debug for Point {
fn fmt<'__a1 , '__a2>(&'__a1 self, __arg0: &'__a2 mut ::std::fmt::Formatter) -> ::std::fmt::Result {
/*
// TODO: somewhat more intelligent impl
match *self {
Point { x: ref __v3, y: ref __v4 } => {
let mut __v5 = ::std::fmt::Formatter::debug_struct(__arg0, "Point");
let _ = ::std::fmt::DebugStruct::field(&mut __v5, "x", __v3);
let _ = ::std::fmt::DebugStruct::field(&mut __v5, "y", __v4);
let __v11 = ::std::fmt::DebugStruct::finish(&mut __v5);
__v11
}
}
*/
let __v0 = self;
let __v1 = __arg0;
let __v3 = &__v0.x;
let __v4 = &__v0.y;
let mut __v5 = ::std::fmt::Formatter::debug_struct(__v1, "Point");
let __v6 = &mut __v5;
let _ = ::std::fmt::DebugStruct::field(__v6, "x", __v3);
let _ = ::std::fmt::DebugStruct::field(__v6, "y", __v4);
let __v11 = ::std::fmt::DebugStruct::finish(__v6);
__v11
}
}
};
let actual = reflect::derive(input, debug::derive);
assert_eq!(actual.to_string(), expected.to_string());
}
#[test]
fn test_generic_debug() {
let input = quote! {
struct Generic<'a, T: ::std::fmt::Debug, U>
where
U: ::std::clone::Clone,
{
t: T,
u: &'a U,
}
};
let expected = quote! {
impl<'__a1, __T0, __T1> ::std::fmt::Debug for Generic<'__a1, __T0, __T1>
where
__T0: ::std::fmt::Debug,
__T1: ::std::clone::Clone,
&'__a1 __T1: ::std::fmt::Debug,
{
fn fmt<'__a2, '__a3>(
&'__a2 self,
__arg0: &'__a3 mut ::std::fmt::Formatter
) -> ::std::fmt::Result {
let __v0 = self;
let __v1 = __arg0;
let __v3 = &__v0.t;
let __v4 = &__v0.u;
let mut __v5 = ::std::fmt::Formatter::debug_struct(__v1, "Generic");
let __v6 = &mut __v5;
let _ = ::std::fmt::DebugStruct::field(__v6, "t", __v3);
let _ = ::std::fmt::DebugStruct::field(__v6, "u", __v4);
let __v11 = ::std::fmt::DebugStruct::finish(__v6);
__v11
}
}
};
let actual = reflect::derive(input, debug::derive);
assert_eq!(actual.to_string(), expected.to_string());
}