1use syn::{parse_quote, FnArg, Receiver, TraitItemMethod};
2
3#[test]
4fn test_by_value() {
5 let TraitItemMethod { sig, .. } = parse_quote! {
6 fn by_value(self: Self);
7 };
8 match sig.receiver() {
9 Some(FnArg::Typed(_)) => (),
10 value => panic!("expected FnArg::Typed, got {:?}", value),
11 }
12}
13
14#[test]
15fn test_by_mut_value() {
16 let TraitItemMethod { sig, .. } = parse_quote! {
17 fn by_mut(mut self: Self);
18 };
19 match sig.receiver() {
20 Some(FnArg::Typed(_)) => (),
21 value => panic!("expected FnArg::Typed, got {:?}", value),
22 }
23}
24
25#[test]
26fn test_by_ref() {
27 let TraitItemMethod { sig, .. } = parse_quote! {
28 fn by_ref(self: &Self);
29 };
30 match sig.receiver() {
31 Some(FnArg::Typed(_)) => (),
32 value => panic!("expected FnArg::Typed, got {:?}", value),
33 }
34}
35
36#[test]
37fn test_by_box() {
38 let TraitItemMethod { sig, .. } = parse_quote! {
39 fn by_box(self: Box<Self>);
40 };
41 match sig.receiver() {
42 Some(FnArg::Typed(_)) => (),
43 value => panic!("expected FnArg::Typed, got {:?}", value),
44 }
45}
46
47#[test]
48fn test_by_pin() {
49 let TraitItemMethod { sig, .. } = parse_quote! {
50 fn by_pin(self: Pin<Self>);
51 };
52 match sig.receiver() {
53 Some(FnArg::Typed(_)) => (),
54 value => panic!("expected FnArg::Typed, got {:?}", value),
55 }
56}
57
58#[test]
59fn test_explicit_type() {
60 let TraitItemMethod { sig, .. } = parse_quote! {
61 fn explicit_type(self: Pin<MyType>);
62 };
63 match sig.receiver() {
64 Some(FnArg::Typed(_)) => (),
65 value => panic!("expected FnArg::Typed, got {:?}", value),
66 }
67}
68
69#[test]
70fn test_value_shorthand() {
71 let TraitItemMethod { sig, .. } = parse_quote! {
72 fn value_shorthand(self);
73 };
74 match sig.receiver() {
75 Some(FnArg::Receiver(Receiver {
76 reference: None,
77 mutability: None,
78 ..
79 })) => (),
80 value => panic!("expected FnArg::Receiver without ref/mut, got {:?}", value),
81 }
82}
83
84#[test]
85fn test_mut_value_shorthand() {
86 let TraitItemMethod { sig, .. } = parse_quote! {
87 fn mut_value_shorthand(mut self);
88 };
89 match sig.receiver() {
90 Some(FnArg::Receiver(Receiver {
91 reference: None,
92 mutability: Some(_),
93 ..
94 })) => (),
95 value => panic!("expected FnArg::Receiver with mut, got {:?}", value),
96 }
97}
98
99#[test]
100fn test_ref_shorthand() {
101 let TraitItemMethod { sig, .. } = parse_quote! {
102 fn ref_shorthand(&self);
103 };
104 match sig.receiver() {
105 Some(FnArg::Receiver(Receiver {
106 reference: Some(_),
107 mutability: None,
108 ..
109 })) => (),
110 value => panic!("expected FnArg::Receiver with ref, got {:?}", value),
111 }
112}
113
114#[test]
115fn test_ref_mut_shorthand() {
116 let TraitItemMethod { sig, .. } = parse_quote! {
117 fn ref_mut_shorthand(&mut self);
118 };
119 match sig.receiver() {
120 Some(FnArg::Receiver(Receiver {
121 reference: Some(_),
122 mutability: Some(_),
123 ..
124 })) => (),
125 value => panic!("expected FnArg::Receiver with ref+mut, got {:?}", value),
126 }
127}
128