1#![allow(clippy::uninlined_format_args)]
2
3#[macro_use]
4mod macros;
5
6use syn::{parse_quote, TraitItemFn};
7
8#[test]
9fn test_by_value() {
10 let TraitItemFn { sig, .. } = parse_quote! {
11 fn by_value(self: Self);
12 };
13 snapshot!(&sig.inputs[0], @r###"
14 FnArg::Receiver(Receiver {
15 colon_token: Some,
16 ty: Type::Path {
17 path: Path {
18 segments: [
19 PathSegment {
20 ident: "Self",
21 },
22 ],
23 },
24 },
25 })
26 "###);
27}
28
29#[test]
30fn test_by_mut_value() {
31 let TraitItemFn { sig, .. } = parse_quote! {
32 fn by_mut(mut self: Self);
33 };
34 snapshot!(&sig.inputs[0], @r###"
35 FnArg::Receiver(Receiver {
36 mutability: Some,
37 colon_token: Some,
38 ty: Type::Path {
39 path: Path {
40 segments: [
41 PathSegment {
42 ident: "Self",
43 },
44 ],
45 },
46 },
47 })
48 "###);
49}
50
51#[test]
52fn test_by_ref() {
53 let TraitItemFn { sig, .. } = parse_quote! {
54 fn by_ref(self: &Self);
55 };
56 snapshot!(&sig.inputs[0], @r###"
57 FnArg::Receiver(Receiver {
58 colon_token: Some,
59 ty: Type::Reference {
60 elem: Type::Path {
61 path: Path {
62 segments: [
63 PathSegment {
64 ident: "Self",
65 },
66 ],
67 },
68 },
69 },
70 })
71 "###);
72}
73
74#[test]
75fn test_by_box() {
76 let TraitItemFn { sig, .. } = parse_quote! {
77 fn by_box(self: Box<Self>);
78 };
79 snapshot!(&sig.inputs[0], @r###"
80 FnArg::Receiver(Receiver {
81 colon_token: Some,
82 ty: Type::Path {
83 path: Path {
84 segments: [
85 PathSegment {
86 ident: "Box",
87 arguments: PathArguments::AngleBracketed {
88 args: [
89 GenericArgument::Type(Type::Path {
90 path: Path {
91 segments: [
92 PathSegment {
93 ident: "Self",
94 },
95 ],
96 },
97 }),
98 ],
99 },
100 },
101 ],
102 },
103 },
104 })
105 "###);
106}
107
108#[test]
109fn test_by_pin() {
110 let TraitItemFn { sig, .. } = parse_quote! {
111 fn by_pin(self: Pin<Self>);
112 };
113 snapshot!(&sig.inputs[0], @r###"
114 FnArg::Receiver(Receiver {
115 colon_token: Some,
116 ty: Type::Path {
117 path: Path {
118 segments: [
119 PathSegment {
120 ident: "Pin",
121 arguments: PathArguments::AngleBracketed {
122 args: [
123 GenericArgument::Type(Type::Path {
124 path: Path {
125 segments: [
126 PathSegment {
127 ident: "Self",
128 },
129 ],
130 },
131 }),
132 ],
133 },
134 },
135 ],
136 },
137 },
138 })
139 "###);
140}
141
142#[test]
143fn test_explicit_type() {
144 let TraitItemFn { sig, .. } = parse_quote! {
145 fn explicit_type(self: Pin<MyType>);
146 };
147 snapshot!(&sig.inputs[0], @r###"
148 FnArg::Receiver(Receiver {
149 colon_token: Some,
150 ty: Type::Path {
151 path: Path {
152 segments: [
153 PathSegment {
154 ident: "Pin",
155 arguments: PathArguments::AngleBracketed {
156 args: [
157 GenericArgument::Type(Type::Path {
158 path: Path {
159 segments: [
160 PathSegment {
161 ident: "MyType",
162 },
163 ],
164 },
165 }),
166 ],
167 },
168 },
169 ],
170 },
171 },
172 })
173 "###);
174}
175
176#[test]
177fn test_value_shorthand() {
178 let TraitItemFn { sig, .. } = parse_quote! {
179 fn value_shorthand(self);
180 };
181 snapshot!(&sig.inputs[0], @r###"
182 FnArg::Receiver(Receiver {
183 ty: Type::Path {
184 path: Path {
185 segments: [
186 PathSegment {
187 ident: "Self",
188 },
189 ],
190 },
191 },
192 })
193 "###);
194}
195
196#[test]
197fn test_mut_value_shorthand() {
198 let TraitItemFn { sig, .. } = parse_quote! {
199 fn mut_value_shorthand(mut self);
200 };
201 snapshot!(&sig.inputs[0], @r###"
202 FnArg::Receiver(Receiver {
203 mutability: Some,
204 ty: Type::Path {
205 path: Path {
206 segments: [
207 PathSegment {
208 ident: "Self",
209 },
210 ],
211 },
212 },
213 })
214 "###);
215}
216
217#[test]
218fn test_ref_shorthand() {
219 let TraitItemFn { sig, .. } = parse_quote! {
220 fn ref_shorthand(&self);
221 };
222 snapshot!(&sig.inputs[0], @r###"
223 FnArg::Receiver(Receiver {
224 reference: Some(None),
225 ty: Type::Reference {
226 elem: Type::Path {
227 path: Path {
228 segments: [
229 PathSegment {
230 ident: "Self",
231 },
232 ],
233 },
234 },
235 },
236 })
237 "###);
238}
239
240#[test]
241fn test_ref_shorthand_with_lifetime() {
242 let TraitItemFn { sig, .. } = parse_quote! {
243 fn ref_shorthand(&'a self);
244 };
245 snapshot!(&sig.inputs[0], @r###"
246 FnArg::Receiver(Receiver {
247 reference: Some(Some(Lifetime {
248 ident: "a",
249 })),
250 ty: Type::Reference {
251 lifetime: Some(Lifetime {
252 ident: "a",
253 }),
254 elem: Type::Path {
255 path: Path {
256 segments: [
257 PathSegment {
258 ident: "Self",
259 },
260 ],
261 },
262 },
263 },
264 })
265 "###);
266}
267
268#[test]
269fn test_ref_mut_shorthand() {
270 let TraitItemFn { sig, .. } = parse_quote! {
271 fn ref_mut_shorthand(&mut self);
272 };
273 snapshot!(&sig.inputs[0], @r###"
274 FnArg::Receiver(Receiver {
275 reference: Some(None),
276 mutability: Some,
277 ty: Type::Reference {
278 mutability: Some,
279 elem: Type::Path {
280 path: Path {
281 segments: [
282 PathSegment {
283 ident: "Self",
284 },
285 ],
286 },
287 },
288 },
289 })
290 "###);
291}
292
293#[test]
294fn test_ref_mut_shorthand_with_lifetime() {
295 let TraitItemFn { sig, .. } = parse_quote! {
296 fn ref_mut_shorthand(&'a mut self);
297 };
298 snapshot!(&sig.inputs[0], @r###"
299 FnArg::Receiver(Receiver {
300 reference: Some(Some(Lifetime {
301 ident: "a",
302 })),
303 mutability: Some,
304 ty: Type::Reference {
305 lifetime: Some(Lifetime {
306 ident: "a",
307 }),
308 mutability: Some,
309 elem: Type::Path {
310 path: Path {
311 segments: [
312 PathSegment {
313 ident: "Self",
314 },
315 ],
316 },
317 },
318 },
319 })
320 "###);
321}
322