1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use googletest::prelude::*;
16 use indoc::indoc;
17 
18 #[test]
matches_struct_containing_single_field() -> Result<()>19 fn matches_struct_containing_single_field() -> Result<()> {
20     #[derive(Debug)]
21     struct AStruct {
22         a_field: u32,
23     }
24     let actual = AStruct { a_field: 123 };
25 
26     verify_that!(actual, matches_pattern!(AStruct { a_field: eq(123) }))
27 }
28 
29 #[test]
matches_struct_containing_two_fields() -> Result<()>30 fn matches_struct_containing_two_fields() -> Result<()> {
31     #[derive(Debug)]
32     struct AStruct {
33         a_field: u32,
34         another_field: u32,
35     }
36     let actual = AStruct { a_field: 123, another_field: 234 };
37 
38     verify_that!(actual, matches_pattern!(AStruct { a_field: eq(123), another_field: eq(234) }))
39 }
40 
41 #[test]
42 #[rustfmt::skip]// Otherwise fmt strips the trailing comma
supports_trailing_comma_with_one_field() -> Result<()>43 fn supports_trailing_comma_with_one_field() -> Result<()> {
44     #[derive(Debug)]
45     struct AStruct {
46         a_field: u32,
47     }
48     let actual = AStruct { a_field: 123 };
49 
50     verify_that!(actual, matches_pattern!(AStruct {
51         a_field: eq(123), // Block reformatting
52     }))
53 }
54 
55 #[test]
supports_trailing_comma_with_two_fields() -> Result<()>56 fn supports_trailing_comma_with_two_fields() -> Result<()> {
57     #[derive(Debug)]
58     struct AStruct {
59         a_field: u32,
60         another_field: u32,
61     }
62     let actual = AStruct { a_field: 123, another_field: 234 };
63 
64     verify_that!(
65         actual,
66         matches_pattern!(AStruct {
67             a_field: eq(123),
68             another_field: eq(234), // Block reformatting
69         })
70     )
71 }
72 
73 #[test]
supports_trailing_comma_with_three_fields() -> Result<()>74 fn supports_trailing_comma_with_three_fields() -> Result<()> {
75     #[derive(Debug)]
76     struct AStruct {
77         a_field: u32,
78         another_field: u32,
79         a_third_field: u32,
80     }
81     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
82 
83     verify_that!(
84         actual,
85         matches_pattern!(AStruct {
86             a_field: eq(123),
87             another_field: eq(234),
88             a_third_field: eq(345),
89         })
90     )
91 }
92 
93 #[test]
matches_struct_containing_nested_struct_with_field() -> Result<()>94 fn matches_struct_containing_nested_struct_with_field() -> Result<()> {
95     #[derive(Debug)]
96     struct AStruct {
97         a_nested_struct: ANestedStruct,
98     }
99     #[derive(Debug)]
100     struct ANestedStruct {
101         a_field: u32,
102     }
103     let actual = AStruct { a_nested_struct: ANestedStruct { a_field: 123 } };
104 
105     verify_that!(
106         actual,
107         matches_pattern!(AStruct { a_nested_struct: pat!(ANestedStruct { a_field: eq(123) }) })
108     )
109 }
110 
111 #[test]
has_correct_assertion_failure_message_for_single_field() -> Result<()>112 fn has_correct_assertion_failure_message_for_single_field() -> Result<()> {
113     #[derive(Debug)]
114     struct AStruct {
115         a_field: u32,
116     }
117     let actual = AStruct { a_field: 123 };
118     let result = verify_that!(actual, matches_pattern!(AStruct { a_field: eq(234) }));
119 
120     verify_that!(
121         result,
122         err(displays_as(contains_substring(indoc! {"
123             Value of: actual
124             Expected: is AStruct which has field `a_field`, which is equal to 234
125             Actual: AStruct { a_field: 123 },
126               which has field `a_field`, which isn't equal to 234
127             "
128         })))
129     )
130 }
131 
132 #[test]
has_correct_assertion_failure_message_for_two_fields() -> Result<()>133 fn has_correct_assertion_failure_message_for_two_fields() -> Result<()> {
134     #[derive(Debug)]
135     struct AStruct {
136         a_field: u32,
137         another_field: u32,
138     }
139     let actual = AStruct { a_field: 123, another_field: 234 };
140     let result = verify_that!(
141         actual,
142         matches_pattern!(AStruct { a_field: eq(234), another_field: eq(123) })
143     );
144     verify_that!(
145         result,
146         err(displays_as(contains_substring(indoc!(
147             "
148             Value of: actual
149             Expected: is AStruct which has all the following properties:
150               * has field `a_field`, which is equal to 234
151               * has field `another_field`, which is equal to 123
152             Actual: AStruct { a_field: 123, another_field: 234 },
153               * which has field `a_field`, which isn't equal to 234
154               * which has field `another_field`, which isn't equal to 123"
155         ))))
156     )
157 }
158 
159 #[test]
has_correct_assertion_failure_message_for_field_and_property() -> Result<()>160 fn has_correct_assertion_failure_message_for_field_and_property() -> Result<()> {
161     #[derive(Debug)]
162     struct AStruct {
163         a_field: u32,
164         another_field: u32,
165     }
166     impl AStruct {
167         fn get_field(&self) -> u32 {
168             self.a_field
169         }
170     }
171     let actual = AStruct { a_field: 123, another_field: 234 };
172     let result = verify_that!(
173         actual,
174         matches_pattern!(AStruct { get_field(): eq(234), another_field: eq(123) })
175     );
176     verify_that!(
177         result,
178         err(displays_as(contains_substring(indoc!(
179             "
180             Value of: actual
181             Expected: is AStruct which has all the following properties:
182               * has property `get_field ()`, which is equal to 234
183               * has field `another_field`, which is equal to 123
184             Actual: AStruct { a_field: 123, another_field: 234 },
185               * whose property `get_field ()` is `123`, which isn't equal to 234
186               * which has field `another_field`, which isn't equal to 123"
187         ))))
188     )
189 }
190 
191 #[test]
has_meaningful_assertion_failure_message_when_wrong_enum_variant_is_used() -> Result<()>192 fn has_meaningful_assertion_failure_message_when_wrong_enum_variant_is_used() -> Result<()> {
193     #[derive(Debug)]
194     enum AnEnum {
195         A(u32),
196         #[allow(unused)]
197         B(u32),
198     }
199     let actual = AnEnum::A(123);
200     let result = verify_that!(actual, matches_pattern!(AnEnum::B(eq(123))));
201 
202     verify_that!(
203         result,
204         err(displays_as(contains_substring(indoc! {"
205             Actual: A(123),
206               which has the wrong enum variant `A`
207             "
208         })))
209     )
210 }
211 
212 #[test]
supports_qualified_struct_names() -> Result<()>213 fn supports_qualified_struct_names() -> Result<()> {
214     mod a_module {
215         #[derive(Debug)]
216         pub(super) struct AStruct {
217             pub(super) a_field: u32,
218         }
219     }
220     let actual = a_module::AStruct { a_field: 123 };
221 
222     verify_that!(actual, matches_pattern!(a_module::AStruct { a_field: eq(123) }))
223 }
224 
225 #[test]
matches_tuple_struct_containing_single_field() -> Result<()>226 fn matches_tuple_struct_containing_single_field() -> Result<()> {
227     #[derive(Debug)]
228     struct AStruct(u32);
229     let actual = AStruct(123);
230 
231     verify_that!(actual, matches_pattern!(AStruct(eq(123))))
232 }
233 
234 #[test]
matches_tuple_struct_containing_two_fields() -> Result<()>235 fn matches_tuple_struct_containing_two_fields() -> Result<()> {
236     #[derive(Debug)]
237     struct AStruct(u32, u32);
238     let actual = AStruct(123, 234);
239 
240     verify_that!(actual, matches_pattern!(AStruct(eq(123), eq(234))))
241 }
242 
243 #[test]
matches_tuple_struct_containing_three_fields() -> Result<()>244 fn matches_tuple_struct_containing_three_fields() -> Result<()> {
245     #[derive(Debug)]
246     struct AStruct(u32, u32, u32);
247     let actual = AStruct(123, 234, 345);
248 
249     verify_that!(actual, matches_pattern!(AStruct(eq(123), eq(234), eq(345))))
250 }
251 
252 #[test]
matches_tuple_struct_containing_four_fields() -> Result<()>253 fn matches_tuple_struct_containing_four_fields() -> Result<()> {
254     #[derive(Debug)]
255     struct AStruct(u32, u32, u32, u32);
256     let actual = AStruct(123, 234, 345, 456);
257 
258     verify_that!(actual, matches_pattern!(AStruct(eq(123), eq(234), eq(345), eq(456))))
259 }
260 
261 #[test]
matches_tuple_struct_containing_five_fields() -> Result<()>262 fn matches_tuple_struct_containing_five_fields() -> Result<()> {
263     #[derive(Debug)]
264     struct AStruct(u32, u32, u32, u32, u32);
265     let actual = AStruct(123, 234, 345, 456, 567);
266 
267     verify_that!(actual, matches_pattern!(AStruct(eq(123), eq(234), eq(345), eq(456), eq(567))))
268 }
269 
270 #[test]
matches_tuple_struct_containing_six_fields() -> Result<()>271 fn matches_tuple_struct_containing_six_fields() -> Result<()> {
272     #[derive(Debug)]
273     struct AStruct(u32, u32, u32, u32, u32, u32);
274     let actual = AStruct(123, 234, 345, 456, 567, 678);
275 
276     verify_that!(
277         actual,
278         matches_pattern!(AStruct(eq(123), eq(234), eq(345), eq(456), eq(567), eq(678)))
279     )
280 }
281 
282 #[test]
matches_tuple_struct_containing_seven_fields() -> Result<()>283 fn matches_tuple_struct_containing_seven_fields() -> Result<()> {
284     #[derive(Debug)]
285     struct AStruct(u32, u32, u32, u32, u32, u32, u32);
286     let actual = AStruct(123, 234, 345, 456, 567, 678, 789);
287 
288     verify_that!(
289         actual,
290         matches_pattern!(AStruct(eq(123), eq(234), eq(345), eq(456), eq(567), eq(678), eq(789)))
291     )
292 }
293 
294 #[test]
matches_tuple_struct_containing_eight_fields() -> Result<()>295 fn matches_tuple_struct_containing_eight_fields() -> Result<()> {
296     #[derive(Debug)]
297     struct AStruct(u32, u32, u32, u32, u32, u32, u32, u32);
298     let actual = AStruct(123, 234, 345, 456, 567, 678, 789, 890);
299 
300     verify_that!(
301         actual,
302         matches_pattern!(AStruct(
303             eq(123),
304             eq(234),
305             eq(345),
306             eq(456),
307             eq(567),
308             eq(678),
309             eq(789),
310             eq(890)
311         ))
312     )
313 }
314 
315 #[test]
matches_tuple_struct_containing_nine_fields() -> Result<()>316 fn matches_tuple_struct_containing_nine_fields() -> Result<()> {
317     #[derive(Debug)]
318     struct AStruct(u32, u32, u32, u32, u32, u32, u32, u32, u32);
319     let actual = AStruct(123, 234, 345, 456, 567, 678, 789, 890, 901);
320 
321     verify_that!(
322         actual,
323         matches_pattern!(AStruct(
324             eq(123),
325             eq(234),
326             eq(345),
327             eq(456),
328             eq(567),
329             eq(678),
330             eq(789),
331             eq(890),
332             eq(901)
333         ))
334     )
335 }
336 
337 #[test]
matches_tuple_struct_containing_ten_fields() -> Result<()>338 fn matches_tuple_struct_containing_ten_fields() -> Result<()> {
339     #[derive(Debug)]
340     struct AStruct(u32, u32, u32, u32, u32, u32, u32, u32, u32, u32);
341     let actual = AStruct(123, 234, 345, 456, 567, 678, 789, 890, 901, 12);
342 
343     verify_that!(
344         actual,
345         matches_pattern!(AStruct(
346             eq(123),
347             eq(234),
348             eq(345),
349             eq(456),
350             eq(567),
351             eq(678),
352             eq(789),
353             eq(890),
354             eq(901),
355             eq(12)
356         ))
357     )
358 }
359 
360 #[test]
matches_tuple_struct_with_trailing_comma() -> Result<()>361 fn matches_tuple_struct_with_trailing_comma() -> Result<()> {
362     #[derive(Debug)]
363     struct AStruct(u32);
364     let actual = AStruct(123);
365 
366     verify_that!(
367         actual,
368         matches_pattern!(AStruct(
369             eq(123), // Keep the trailing comma, block reformatting
370         ))
371     )
372 }
373 
374 #[test]
matches_tuple_struct_with_two_fields_and_trailing_comma() -> Result<()>375 fn matches_tuple_struct_with_two_fields_and_trailing_comma() -> Result<()> {
376     #[derive(Debug)]
377     struct AStruct(u32, u32);
378     let actual = AStruct(123, 234);
379 
380     verify_that!(
381         actual,
382         matches_pattern!(AStruct(
383             eq(123),
384             eq(234), // Keep the trailing comma, block reformatting
385         ))
386     )
387 }
388 
389 #[test]
matches_enum_without_field() -> Result<()>390 fn matches_enum_without_field() -> Result<()> {
391     #[derive(Debug)]
392     enum AnEnum {
393         A,
394     }
395     let actual = AnEnum::A;
396 
397     verify_that!(actual, matches_pattern!(AnEnum::A))
398 }
399 
400 #[rustversion::before(1.76)]
401 const ANENUM_A_REPR: &str = "AnEnum :: A";
402 
403 #[rustversion::since(1.76)]
404 const ANENUM_A_REPR: &str = "AnEnum::A";
405 
406 #[test]
generates_correct_failure_output_when_enum_variant_without_field_is_not_matched() -> Result<()>407 fn generates_correct_failure_output_when_enum_variant_without_field_is_not_matched() -> Result<()> {
408     #[derive(Debug)]
409     enum AnEnum {
410         #[allow(unused)]
411         A,
412         B,
413     }
414     let actual = AnEnum::B;
415 
416     let result = verify_that!(actual, matches_pattern!(AnEnum::A));
417 
418     verify_that!(result, err(displays_as(contains_substring(format!("is not {ANENUM_A_REPR}")))))
419 }
420 
421 #[test]
generates_correct_failure_output_when_enum_variant_without_field_is_matched() -> Result<()>422 fn generates_correct_failure_output_when_enum_variant_without_field_is_matched() -> Result<()> {
423     #[derive(Debug)]
424     enum AnEnum {
425         A,
426     }
427     let actual = AnEnum::A;
428 
429     let result = verify_that!(actual, not(matches_pattern!(AnEnum::A)));
430 
431     verify_that!(result, err(displays_as(contains_substring(format!("is {ANENUM_A_REPR}")))))
432 }
433 
434 #[test]
matches_enum_with_field() -> Result<()>435 fn matches_enum_with_field() -> Result<()> {
436     #[derive(Debug)]
437     enum AnEnum {
438         A(u32),
439     }
440     let actual = AnEnum::A(123);
441 
442     verify_that!(actual, matches_pattern!(AnEnum::A(eq(123))))
443 }
444 
445 #[test]
does_not_match_wrong_enum_value() -> Result<()>446 fn does_not_match_wrong_enum_value() -> Result<()> {
447     #[derive(Debug)]
448     enum AnEnum {
449         #[allow(unused)]
450         A(u32),
451         B,
452     }
453     let actual = AnEnum::B;
454 
455     verify_that!(actual, not(matches_pattern!(AnEnum::A(eq(123)))))
456 }
457 
458 #[test]
includes_enum_variant_in_description_with_field() -> Result<()>459 fn includes_enum_variant_in_description_with_field() -> Result<()> {
460     #[derive(Debug)]
461     enum AnEnum {
462         A(u32),
463     }
464     let actual = AnEnum::A(123);
465 
466     let result = verify_that!(actual, matches_pattern!(AnEnum::A(eq(234))));
467 
468     verify_that!(
469         result,
470         err(displays_as(contains_substring(format!(
471             "Expected: is {ANENUM_A_REPR} which has field `0`"
472         ))))
473     )
474 }
475 
476 #[test]
includes_enum_variant_in_negative_description_with_field() -> Result<()>477 fn includes_enum_variant_in_negative_description_with_field() -> Result<()> {
478     #[derive(Debug)]
479     enum AnEnum {
480         A(u32),
481     }
482     let actual = AnEnum::A(123);
483 
484     let result = verify_that!(actual, not(matches_pattern!(AnEnum::A(eq(123)))));
485 
486     verify_that!(
487         result,
488         err(displays_as(contains_substring(format!(
489             "Expected: is not {ANENUM_A_REPR} which has field `0`, which is equal to"
490         ))))
491     )
492 }
493 
494 #[test]
includes_enum_variant_in_description_with_two_fields() -> Result<()>495 fn includes_enum_variant_in_description_with_two_fields() -> Result<()> {
496     #[derive(Debug)]
497     enum AnEnum {
498         A(u32, u32),
499     }
500     let actual = AnEnum::A(123, 234);
501 
502     let result = verify_that!(actual, matches_pattern!(AnEnum::A(eq(234), eq(234))));
503 
504     verify_that!(
505         result,
506         err(displays_as(contains_substring(format!(
507             "Expected: is {ANENUM_A_REPR} which has all the following properties"
508         ))))
509     )
510 }
511 
512 #[test]
includes_enum_variant_in_description_with_three_fields() -> Result<()>513 fn includes_enum_variant_in_description_with_three_fields() -> Result<()> {
514     #[derive(Debug)]
515     enum AnEnum {
516         A(u32, u32, u32),
517     }
518     let actual = AnEnum::A(123, 234, 345);
519 
520     let result = verify_that!(actual, matches_pattern!(AnEnum::A(eq(234), eq(234), eq(345))));
521 
522     verify_that!(
523         result,
524         err(displays_as(contains_substring(format!(
525             "Expected: is {ANENUM_A_REPR} which has all the following properties"
526         ))))
527     )
528 }
529 
530 #[test]
includes_enum_variant_in_description_with_named_field() -> Result<()>531 fn includes_enum_variant_in_description_with_named_field() -> Result<()> {
532     #[derive(Debug)]
533     enum AnEnum {
534         A { field: u32 },
535     }
536     let actual = AnEnum::A { field: 123 };
537 
538     let result = verify_that!(actual, matches_pattern!(AnEnum::A { field: eq(234) }));
539 
540     verify_that!(
541         result,
542         err(displays_as(contains_substring(format!(
543             "Expected: is {ANENUM_A_REPR} which has field `field`"
544         ))))
545     )
546 }
547 
548 #[test]
includes_enum_variant_in_description_with_two_named_fields() -> Result<()>549 fn includes_enum_variant_in_description_with_two_named_fields() -> Result<()> {
550     #[derive(Debug)]
551     enum AnEnum {
552         A { field: u32, another_field: u32 },
553     }
554     let actual = AnEnum::A { field: 123, another_field: 234 };
555 
556     let result = verify_that!(
557         actual,
558         matches_pattern!(AnEnum::A { field: eq(234), another_field: eq(234) })
559     );
560 
561     verify_that!(
562         result,
563         err(displays_as(contains_substring(format!(
564             "Expected: is {ANENUM_A_REPR} which has all the following properties"
565         ))))
566     )
567 }
568 
569 #[test]
includes_struct_name_in_description_with_property() -> Result<()>570 fn includes_struct_name_in_description_with_property() -> Result<()> {
571     #[derive(Debug)]
572     struct AStruct {
573         field: u32,
574     }
575     impl AStruct {
576         fn get_field(&self) -> u32 {
577             self.field
578         }
579     }
580     let actual = AStruct { field: 123 };
581 
582     let result = verify_that!(actual, matches_pattern!(AStruct { get_field(): eq(234) }));
583 
584     verify_that!(
585         result,
586         err(displays_as(contains_substring(
587             "Expected: is AStruct which has property `get_field ()`"
588         )))
589     )
590 }
591 
592 #[test]
includes_struct_name_in_description_with_ref_property() -> Result<()>593 fn includes_struct_name_in_description_with_ref_property() -> Result<()> {
594     #[derive(Debug)]
595     struct AStruct {
596         field: u32,
597     }
598     impl AStruct {
599         fn get_field(&self) -> &u32 {
600             &self.field
601         }
602     }
603     let actual = AStruct { field: 123 };
604 
605     let result = verify_that!(actual, matches_pattern!(AStruct { *get_field(): eq(234) }));
606 
607     verify_that!(
608         result,
609         err(displays_as(contains_substring(
610             "Expected: is AStruct which has property `get_field ()`"
611         )))
612     )
613 }
614 
615 #[test]
includes_struct_name_in_description_with_property_after_field() -> Result<()>616 fn includes_struct_name_in_description_with_property_after_field() -> Result<()> {
617     #[derive(Debug)]
618     struct AStruct {
619         field: u32,
620     }
621     impl AStruct {
622         fn get_field(&self) -> u32 {
623             self.field
624         }
625     }
626     let actual = AStruct { field: 123 };
627 
628     let result =
629         verify_that!(actual, matches_pattern!(AStruct { field: eq(123), get_field(): eq(234) }));
630 
631     verify_that!(
632         result,
633         err(displays_as(contains_substring(
634             "Expected: is AStruct which has all the following properties"
635         )))
636     )
637 }
638 
639 #[test]
includes_struct_name_in_description_with_ref_property_after_field() -> Result<()>640 fn includes_struct_name_in_description_with_ref_property_after_field() -> Result<()> {
641     #[derive(Debug)]
642     struct AStruct {
643         field: u32,
644     }
645     impl AStruct {
646         fn get_field(&self) -> &u32 {
647             &self.field
648         }
649     }
650     let actual = AStruct { field: 123 };
651 
652     let result =
653         verify_that!(actual, matches_pattern!(AStruct { field: eq(123), *get_field(): eq(234) }));
654 
655     verify_that!(
656         result,
657         err(displays_as(contains_substring(
658             "Expected: is AStruct which has all the following properties"
659         )))
660     )
661 }
662 
663 #[test]
matches_struct_with_a_method() -> Result<()>664 fn matches_struct_with_a_method() -> Result<()> {
665     #[derive(Debug)]
666     struct AStruct {
667         a_field: u32,
668     }
669 
670     impl AStruct {
671         fn get_field(&self) -> u32 {
672             self.a_field
673         }
674     }
675 
676     let actual = AStruct { a_field: 123 };
677 
678     verify_that!(actual, matches_pattern!(AStruct { get_field(): eq(123) }))
679 }
680 
681 #[test]
matches_struct_with_a_method_and_trailing_comma() -> Result<()>682 fn matches_struct_with_a_method_and_trailing_comma() -> Result<()> {
683     #[derive(Debug)]
684     struct AStruct {
685         a_field: u32,
686     }
687 
688     impl AStruct {
689         fn get_field(&self) -> u32 {
690             self.a_field
691         }
692     }
693 
694     let actual = AStruct { a_field: 123 };
695 
696     verify_that!(actual, matches_pattern!(AStruct { get_field(): eq(123), }))
697 }
698 
699 #[test]
matches_struct_with_a_method_taking_parameter() -> Result<()>700 fn matches_struct_with_a_method_taking_parameter() -> Result<()> {
701     #[derive(Debug)]
702     struct AStruct {
703         a_field: u32,
704     }
705 
706     impl AStruct {
707         fn add_to_field(&self, a: u32) -> u32 {
708             self.a_field + a
709         }
710     }
711 
712     let actual = AStruct { a_field: 1 };
713 
714     verify_that!(actual, matches_pattern!(AStruct { add_to_field(2): eq(3) }))
715 }
716 
717 #[test]
matches_struct_with_a_method_taking_two_parameters() -> Result<()>718 fn matches_struct_with_a_method_taking_two_parameters() -> Result<()> {
719     #[derive(Debug)]
720     struct AStruct {
721         a_field: u32,
722     }
723 
724     impl AStruct {
725         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
726             self.a_field + a * b
727         }
728     }
729 
730     let actual = AStruct { a_field: 1 };
731 
732     verify_that!(actual, matches_pattern!(AStruct { add_product_to_field(2, 3): eq(7) }))
733 }
734 
735 #[test]
matches_struct_with_a_method_taking_enum_value_parameter() -> Result<()>736 fn matches_struct_with_a_method_taking_enum_value_parameter() -> Result<()> {
737     enum AnEnum {
738         AVariant,
739     }
740 
741     #[derive(Debug)]
742     struct AStruct {
743         a_field: u32,
744     }
745 
746     impl AStruct {
747         fn get_a_field(&self, _value: AnEnum) -> u32 {
748             self.a_field
749         }
750     }
751 
752     let actual = AStruct { a_field: 1 };
753 
754     verify_that!(actual, matches_pattern!(AStruct { get_a_field(AnEnum::AVariant): eq(1) }))
755 }
756 
757 #[test]
matches_struct_with_a_method_taking_two_parameters_with_trailing_comma() -> Result<()>758 fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma() -> Result<()> {
759     #[derive(Debug)]
760     struct AStruct {
761         a_field: u32,
762     }
763 
764     impl AStruct {
765         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
766             self.a_field + a * b
767         }
768     }
769 
770     let actual = AStruct { a_field: 1 };
771 
772     verify_that!(actual, matches_pattern!(AStruct { add_product_to_field(2, 3,): eq(7) }))
773 }
774 
775 #[test]
matches_struct_with_a_method_returning_a_reference() -> Result<()>776 fn matches_struct_with_a_method_returning_a_reference() -> Result<()> {
777     #[derive(Debug)]
778     struct AStruct {
779         a_field: u32,
780     }
781 
782     impl AStruct {
783         fn get_field_ref(&self) -> &u32 {
784             &self.a_field
785         }
786     }
787 
788     let actual = AStruct { a_field: 123 };
789 
790     verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(): eq(123) }))
791 }
792 
793 #[test]
matches_struct_with_a_method_returning_a_reference_with_trailing_comma() -> Result<()>794 fn matches_struct_with_a_method_returning_a_reference_with_trailing_comma() -> Result<()> {
795     #[derive(Debug)]
796     struct AStruct {
797         a_field: u32,
798     }
799 
800     impl AStruct {
801         fn get_field_ref(&self) -> &u32 {
802             &self.a_field
803         }
804     }
805 
806     let actual = AStruct { a_field: 123 };
807 
808     verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(): eq(123), }))
809 }
810 
811 #[test]
matches_struct_with_a_method_taking_two_parameters_ret_ref() -> Result<()>812 fn matches_struct_with_a_method_taking_two_parameters_ret_ref() -> Result<()> {
813     #[derive(Debug)]
814     struct AStruct {
815         a_field: u32,
816     }
817 
818     impl AStruct {
819         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
820             &self.a_field
821         }
822     }
823 
824     let actual = AStruct { a_field: 1 };
825 
826     verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(2, 3): eq(1) }))
827 }
828 
829 #[test]
matches_struct_with_a_method_returning_reference_taking_enum_value_parameter() -> Result<()>830 fn matches_struct_with_a_method_returning_reference_taking_enum_value_parameter() -> Result<()> {
831     enum AnEnum {
832         AVariant,
833     }
834 
835     #[derive(Debug)]
836     struct AStruct {
837         a_field: u32,
838     }
839 
840     impl AStruct {
841         fn get_field_ref(&self, _value: AnEnum) -> &u32 {
842             &self.a_field
843         }
844     }
845 
846     let actual = AStruct { a_field: 1 };
847 
848     verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(AnEnum::AVariant): eq(1) }))
849 }
850 
851 #[test]
matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref() -> Result<()>852 fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref() -> Result<()> {
853     #[derive(Debug)]
854     struct AStruct {
855         a_field: u32,
856     }
857 
858     impl AStruct {
859         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
860             &self.a_field
861         }
862     }
863 
864     let actual = AStruct { a_field: 1 };
865 
866     verify_that!(actual, matches_pattern!(AStruct { *get_field_ref(2, 3,): eq(1) }))
867 }
868 
869 #[test]
matches_struct_with_a_method_followed_by_a_field() -> Result<()>870 fn matches_struct_with_a_method_followed_by_a_field() -> Result<()> {
871     #[derive(Debug)]
872     struct AStruct {
873         a_field: u32,
874         another_field: u32,
875     }
876 
877     impl AStruct {
878         fn get_field(&self) -> u32 {
879             self.a_field
880         }
881     }
882 
883     let actual = AStruct { a_field: 123, another_field: 234 };
884 
885     verify_that!(actual, matches_pattern!(AStruct { get_field(): eq(123), another_field: eq(234) }))
886 }
887 
888 #[test]
matches_struct_with_a_method_followed_by_a_field_with_trailing_comma() -> Result<()>889 fn matches_struct_with_a_method_followed_by_a_field_with_trailing_comma() -> Result<()> {
890     #[derive(Debug)]
891     struct AStruct {
892         a_field: u32,
893         another_field: u32,
894     }
895 
896     impl AStruct {
897         fn get_field(&self) -> u32 {
898             self.a_field
899         }
900     }
901 
902     let actual = AStruct { a_field: 123, another_field: 234 };
903 
904     verify_that!(
905         actual,
906         matches_pattern!(AStruct { get_field(): eq(123), another_field: eq(234), })
907     )
908 }
909 
910 #[test]
matches_struct_with_a_method_taking_two_parameters_and_field() -> Result<()>911 fn matches_struct_with_a_method_taking_two_parameters_and_field() -> Result<()> {
912     #[derive(Debug)]
913     struct AStruct {
914         a_field: u32,
915         another_field: u32,
916     }
917 
918     impl AStruct {
919         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
920             self.a_field + a * b
921         }
922     }
923 
924     let actual = AStruct { a_field: 1, another_field: 123 };
925 
926     verify_that!(
927         actual,
928         matches_pattern!(AStruct { add_product_to_field(2, 3): eq(7), another_field: eq(123) })
929     )
930 }
931 
932 #[test]
matches_struct_with_a_method_taking_enum_value_parameter_followed_by_field() -> Result<()>933 fn matches_struct_with_a_method_taking_enum_value_parameter_followed_by_field() -> Result<()> {
934     enum AnEnum {
935         AVariant,
936     }
937 
938     #[derive(Debug)]
939     struct AStruct {
940         a_field: u32,
941         another_field: u32,
942     }
943 
944     impl AStruct {
945         fn get_field(&self, _value: AnEnum) -> u32 {
946             self.a_field
947         }
948     }
949 
950     let actual = AStruct { a_field: 1, another_field: 2 };
951 
952     verify_that!(
953         actual,
954         matches_pattern!(AStruct { get_field(AnEnum::AVariant): eq(1), another_field: eq(2) })
955     )
956 }
957 
958 #[test]
matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_and_field() -> Result<()>959 fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_and_field() -> Result<()>
960 {
961     #[derive(Debug)]
962     struct AStruct {
963         a_field: u32,
964         another_field: u32,
965     }
966 
967     impl AStruct {
968         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
969             self.a_field + a * b
970         }
971     }
972 
973     let actual = AStruct { a_field: 1, another_field: 123 };
974 
975     verify_that!(
976         actual,
977         matches_pattern!(AStruct { add_product_to_field(2, 3,): eq(7), another_field: eq(123) })
978     )
979 }
980 
981 #[test]
matches_struct_with_a_method_returning_reference_followed_by_a_field() -> Result<()>982 fn matches_struct_with_a_method_returning_reference_followed_by_a_field() -> Result<()> {
983     #[derive(Debug)]
984     struct AStruct {
985         a_field: u32,
986         another_field: u32,
987     }
988 
989     impl AStruct {
990         fn get_field_ref(&self) -> &u32 {
991             &self.a_field
992         }
993     }
994 
995     let actual = AStruct { a_field: 123, another_field: 234 };
996 
997     verify_that!(
998         actual,
999         matches_pattern!(AStruct { *get_field_ref(): eq(123), another_field: eq(234) })
1000     )
1001 }
1002 
1003 #[test]
matches_struct_with_a_method_returning_reference_followed_by_a_field_with_trailing_comma() -> Result<()>1004 fn matches_struct_with_a_method_returning_reference_followed_by_a_field_with_trailing_comma()
1005 -> Result<()> {
1006     #[derive(Debug)]
1007     struct AStruct {
1008         a_field: u32,
1009         another_field: u32,
1010     }
1011 
1012     impl AStruct {
1013         fn get_field_ref(&self) -> &u32 {
1014             &self.a_field
1015         }
1016     }
1017 
1018     let actual = AStruct { a_field: 123, another_field: 234 };
1019 
1020     verify_that!(
1021         actual,
1022         matches_pattern!(AStruct { *get_field_ref(): eq(123), another_field: eq(234), })
1023     )
1024 }
1025 
1026 #[test]
matches_struct_with_a_method_taking_two_parameters_ret_ref_and_field() -> Result<()>1027 fn matches_struct_with_a_method_taking_two_parameters_ret_ref_and_field() -> Result<()> {
1028     #[derive(Debug)]
1029     struct AStruct {
1030         a_field: u32,
1031         another_field: u32,
1032     }
1033 
1034     impl AStruct {
1035         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1036             &self.a_field
1037         }
1038     }
1039 
1040     let actual = AStruct { a_field: 1, another_field: 123 };
1041 
1042     verify_that!(
1043         actual,
1044         matches_pattern!(AStruct { *get_field_ref(2, 3): eq(1), another_field: eq(123) })
1045     )
1046 }
1047 
1048 #[test]
matches_struct_with_a_method_taking_enum_value_param_ret_ref_followed_by_field() -> Result<()>1049 fn matches_struct_with_a_method_taking_enum_value_param_ret_ref_followed_by_field() -> Result<()> {
1050     enum AnEnum {
1051         AVariant,
1052     }
1053 
1054     #[derive(Debug)]
1055     struct AStruct {
1056         a_field: u32,
1057         another_field: u32,
1058     }
1059 
1060     impl AStruct {
1061         fn get_field_ref(&self, _value: AnEnum) -> &u32 {
1062             &self.a_field
1063         }
1064     }
1065 
1066     let actual = AStruct { a_field: 1, another_field: 2 };
1067 
1068     verify_that!(
1069         actual,
1070         matches_pattern!(AStruct { *get_field_ref(AnEnum::AVariant): eq(1), another_field: eq(2) })
1071     )
1072 }
1073 
1074 #[test]
matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref_and_field() -> Result<()>1075 fn matches_struct_with_a_method_taking_two_parameters_with_trailing_comma_ret_ref_and_field()
1076 -> Result<()> {
1077     #[derive(Debug)]
1078     struct AStruct {
1079         a_field: u32,
1080         another_field: u32,
1081     }
1082 
1083     impl AStruct {
1084         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1085             &self.a_field
1086         }
1087     }
1088 
1089     let actual = AStruct { a_field: 1, another_field: 123 };
1090 
1091     verify_that!(
1092         actual,
1093         matches_pattern!(AStruct { *get_field_ref(2, 3,): eq(1), another_field: eq(123) })
1094     )
1095 }
1096 
1097 #[test]
matches_struct_with_a_field_followed_by_a_method() -> Result<()>1098 fn matches_struct_with_a_field_followed_by_a_method() -> Result<()> {
1099     #[derive(Debug)]
1100     struct AStruct {
1101         a_field: u32,
1102         another_field: u32,
1103     }
1104 
1105     impl AStruct {
1106         fn get_field(&self) -> u32 {
1107             self.a_field
1108         }
1109     }
1110 
1111     let actual = AStruct { a_field: 123, another_field: 234 };
1112 
1113     verify_that!(actual, matches_pattern!(AStruct { another_field: eq(234), get_field(): eq(123) }))
1114 }
1115 
1116 #[test]
matches_struct_with_a_field_followed_by_a_method_with_trailing_comma() -> Result<()>1117 fn matches_struct_with_a_field_followed_by_a_method_with_trailing_comma() -> Result<()> {
1118     #[derive(Debug)]
1119     struct AStruct {
1120         a_field: u32,
1121         another_field: u32,
1122     }
1123 
1124     impl AStruct {
1125         fn get_field(&self) -> u32 {
1126             self.a_field
1127         }
1128     }
1129 
1130     let actual = AStruct { a_field: 123, another_field: 234 };
1131 
1132     verify_that!(
1133         actual,
1134         matches_pattern!(AStruct { another_field: eq(234), get_field(): eq(123), })
1135     )
1136 }
1137 
1138 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params() -> Result<()>1139 fn matches_struct_with_a_field_followed_by_a_method_with_params() -> Result<()> {
1140     #[derive(Debug)]
1141     struct AStruct {
1142         a_field: u32,
1143         another_field: u32,
1144     }
1145 
1146     impl AStruct {
1147         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
1148             self.a_field + a * b
1149         }
1150     }
1151 
1152     let actual = AStruct { a_field: 1, another_field: 234 };
1153 
1154     verify_that!(
1155         actual,
1156         matches_pattern!(AStruct { another_field: eq(234), add_product_to_field(2, 3): eq(7) })
1157     )
1158 }
1159 
1160 #[test]
matches_struct_with_field_followed_by_method_taking_enum_value_param() -> Result<()>1161 fn matches_struct_with_field_followed_by_method_taking_enum_value_param() -> Result<()> {
1162     enum AnEnum {
1163         AVariant,
1164     }
1165 
1166     #[derive(Debug)]
1167     struct AStruct {
1168         a_field: u32,
1169         another_field: u32,
1170     }
1171 
1172     impl AStruct {
1173         fn get_field(&self, _value: AnEnum) -> u32 {
1174             self.a_field
1175         }
1176     }
1177 
1178     let actual = AStruct { a_field: 1, another_field: 2 };
1179 
1180     verify_that!(
1181         actual,
1182         matches_pattern!(AStruct { another_field: eq(2), get_field(AnEnum::AVariant): eq(1) })
1183     )
1184 }
1185 
1186 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma() -> Result<()>1187 fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma() -> Result<()> {
1188     #[derive(Debug)]
1189     struct AStruct {
1190         a_field: u32,
1191         another_field: u32,
1192     }
1193 
1194     impl AStruct {
1195         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
1196             self.a_field + a * b
1197         }
1198     }
1199 
1200     let actual = AStruct { a_field: 1, another_field: 234 };
1201 
1202     verify_that!(
1203         actual,
1204         matches_pattern!(AStruct { another_field: eq(234), add_product_to_field(2, 3,): eq(7) })
1205     )
1206 }
1207 
1208 #[test]
matches_struct_with_a_field_followed_by_a_method_returning_reference() -> Result<()>1209 fn matches_struct_with_a_field_followed_by_a_method_returning_reference() -> Result<()> {
1210     #[derive(Debug)]
1211     struct AStruct {
1212         a_field: u32,
1213         another_field: u32,
1214     }
1215 
1216     impl AStruct {
1217         fn get_field_ref(&self) -> &u32 {
1218             &self.a_field
1219         }
1220     }
1221 
1222     let actual = AStruct { a_field: 123, another_field: 234 };
1223 
1224     verify_that!(
1225         actual,
1226         matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(): eq(123) })
1227     )
1228 }
1229 
1230 #[test]
matches_struct_with_a_field_followed_by_a_method_returning_ref_and_trailing_comma() -> Result<()>1231 fn matches_struct_with_a_field_followed_by_a_method_returning_ref_and_trailing_comma() -> Result<()>
1232 {
1233     #[derive(Debug)]
1234     struct AStruct {
1235         a_field: u32,
1236         another_field: u32,
1237     }
1238 
1239     impl AStruct {
1240         fn get_field_ref(&self) -> &u32 {
1241             &self.a_field
1242         }
1243     }
1244 
1245     let actual = AStruct { a_field: 123, another_field: 234 };
1246 
1247     verify_that!(
1248         actual,
1249         matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(): eq(123), })
1250     )
1251 }
1252 
1253 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref() -> Result<()>1254 fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref() -> Result<()> {
1255     #[derive(Debug)]
1256     struct AStruct {
1257         a_field: u32,
1258         another_field: u32,
1259     }
1260 
1261     impl AStruct {
1262         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1263             &self.a_field
1264         }
1265     }
1266 
1267     let actual = AStruct { a_field: 123, another_field: 234 };
1268 
1269     verify_that!(
1270         actual,
1271         matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(2, 3): eq(123) })
1272     )
1273 }
1274 
1275 #[test]
matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref() -> Result<()>1276 fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref() -> Result<()> {
1277     enum AnEnum {
1278         AVariant,
1279     }
1280 
1281     #[derive(Debug)]
1282     struct AStruct {
1283         a_field: u32,
1284         another_field: u32,
1285     }
1286 
1287     impl AStruct {
1288         fn get_field_ref(&self, _value: AnEnum) -> &u32 {
1289             &self.a_field
1290         }
1291     }
1292 
1293     let actual = AStruct { a_field: 1, another_field: 2 };
1294 
1295     verify_that!(
1296         actual,
1297         matches_pattern!(AStruct { another_field: eq(2), *get_field_ref(AnEnum::AVariant): eq(1) })
1298     )
1299 }
1300 
1301 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_ret_ref() -> Result<()>1302 fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_ret_ref()
1303 -> Result<()> {
1304     #[derive(Debug)]
1305     struct AStruct {
1306         a_field: u32,
1307         another_field: u32,
1308     }
1309 
1310     impl AStruct {
1311         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1312             &self.a_field
1313         }
1314     }
1315 
1316     let actual = AStruct { a_field: 123, another_field: 234 };
1317 
1318     verify_that!(
1319         actual,
1320         matches_pattern!(AStruct { another_field: eq(234), *get_field_ref(2, 3,): eq(123) })
1321     )
1322 }
1323 
1324 #[test]
matches_struct_with_a_field_followed_by_a_method_followed_by_a_field() -> Result<()>1325 fn matches_struct_with_a_field_followed_by_a_method_followed_by_a_field() -> Result<()> {
1326     #[derive(Debug)]
1327     struct AStruct {
1328         a_field: u32,
1329         another_field: u32,
1330         a_third_field: u32,
1331     }
1332 
1333     impl AStruct {
1334         fn get_field(&self) -> u32 {
1335             self.a_field
1336         }
1337     }
1338 
1339     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1340 
1341     verify_that!(
1342         actual,
1343         matches_pattern!(AStruct {
1344             another_field: eq(234),
1345             get_field(): eq(123),
1346             a_third_field: eq(345)
1347         })
1348     )
1349 }
1350 
1351 #[test]
matches_struct_with_a_field_followed_by_a_method_followed_by_a_field_with_trailing_comma() -> Result<()>1352 fn matches_struct_with_a_field_followed_by_a_method_followed_by_a_field_with_trailing_comma()
1353 -> Result<()> {
1354     #[derive(Debug)]
1355     struct AStruct {
1356         a_field: u32,
1357         another_field: u32,
1358         a_third_field: u32,
1359     }
1360 
1361     impl AStruct {
1362         fn get_field(&self) -> u32 {
1363             self.a_field
1364         }
1365     }
1366 
1367     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1368 
1369     verify_that!(
1370         actual,
1371         matches_pattern!(AStruct {
1372             another_field: eq(234),
1373             get_field(): eq(123),
1374             a_third_field: eq(345),
1375         })
1376     )
1377 }
1378 
1379 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_followed_by_a_field() -> Result<()>1380 fn matches_struct_with_a_field_followed_by_a_method_with_params_followed_by_a_field() -> Result<()>
1381 {
1382     #[derive(Debug)]
1383     struct AStruct {
1384         a_field: u32,
1385         another_field: u32,
1386         a_third_field: u32,
1387     }
1388 
1389     impl AStruct {
1390         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
1391             self.a_field + a * b
1392         }
1393     }
1394 
1395     let actual = AStruct { a_field: 1, another_field: 234, a_third_field: 345 };
1396 
1397     verify_that!(
1398         actual,
1399         matches_pattern!(AStruct {
1400             another_field: eq(234),
1401             add_product_to_field(2, 3): eq(7),
1402             a_third_field: eq(345),
1403         })
1404     )
1405 }
1406 
1407 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_followed_by_a_field() -> Result<()>1408 fn matches_struct_with_a_field_followed_by_a_method_with_params_and_trailing_comma_followed_by_a_field()
1409 -> Result<()> {
1410     #[derive(Debug)]
1411     struct AStruct {
1412         a_field: u32,
1413         another_field: u32,
1414         a_third_field: u32,
1415     }
1416 
1417     impl AStruct {
1418         fn add_product_to_field(&self, a: u32, b: u32) -> u32 {
1419             self.a_field + a * b
1420         }
1421     }
1422 
1423     let actual = AStruct { a_field: 1, another_field: 234, a_third_field: 345 };
1424 
1425     verify_that!(
1426         actual,
1427         matches_pattern!(AStruct {
1428             another_field: eq(234),
1429             add_product_to_field(2, 3,): eq(7),
1430             a_third_field: eq(345),
1431         })
1432     )
1433 }
1434 
1435 #[test]
matches_struct_with_field_followed_by_method_taking_enum_value_param_followed_by_field() -> Result<()>1436 fn matches_struct_with_field_followed_by_method_taking_enum_value_param_followed_by_field()
1437 -> Result<()> {
1438     enum AnEnum {
1439         AVariant,
1440     }
1441 
1442     #[derive(Debug)]
1443     struct AStruct {
1444         a_field: u32,
1445         another_field: u32,
1446         a_third_field: u32,
1447     }
1448 
1449     impl AStruct {
1450         fn get_field(&self, _value: AnEnum) -> u32 {
1451             self.a_field
1452         }
1453     }
1454 
1455     let actual = AStruct { a_field: 1, another_field: 2, a_third_field: 3 };
1456 
1457     verify_that!(
1458         actual,
1459         matches_pattern!(AStruct {
1460             another_field: eq(2),
1461             get_field(AnEnum::AVariant): eq(1),
1462             a_third_field: eq(3),
1463         })
1464     )
1465 }
1466 
1467 #[test]
matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field() -> Result<()>1468 fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field() -> Result<()> {
1469     #[derive(Debug)]
1470     struct AStruct {
1471         a_field: u32,
1472         another_field: u32,
1473         a_third_field: u32,
1474     }
1475 
1476     impl AStruct {
1477         fn get_field_ref(&self) -> &u32 {
1478             &self.a_field
1479         }
1480     }
1481 
1482     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1483 
1484     verify_that!(
1485         actual,
1486         matches_pattern!(AStruct {
1487             another_field: eq(234),
1488             *get_field_ref(): eq(123),
1489             a_third_field: eq(345)
1490         })
1491     )
1492 }
1493 
1494 #[test]
matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_with_trailing_comma() -> Result<()>1495 fn matches_struct_with_a_field_followed_by_a_method_ret_ref_followed_by_a_field_with_trailing_comma()
1496 -> Result<()> {
1497     #[derive(Debug)]
1498     struct AStruct {
1499         a_field: u32,
1500         another_field: u32,
1501         a_third_field: u32,
1502     }
1503 
1504     impl AStruct {
1505         fn get_field_ref(&self) -> &u32 {
1506             &self.a_field
1507         }
1508     }
1509 
1510     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1511 
1512     verify_that!(
1513         actual,
1514         matches_pattern!(AStruct {
1515             another_field: eq(234),
1516             *get_field_ref(): eq(123),
1517             a_third_field: eq(345),
1518         })
1519     )
1520 }
1521 
1522 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed_by_a_field() -> Result<()>1523 fn matches_struct_with_a_field_followed_by_a_method_with_params_ret_ref_followed_by_a_field()
1524 -> Result<()> {
1525     #[derive(Debug)]
1526     struct AStruct {
1527         a_field: u32,
1528         another_field: u32,
1529         a_third_field: u32,
1530     }
1531 
1532     impl AStruct {
1533         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1534             &self.a_field
1535         }
1536     }
1537 
1538     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1539 
1540     verify_that!(
1541         actual,
1542         matches_pattern!(AStruct {
1543             another_field: eq(234),
1544             *get_field_ref(2, 3): eq(123),
1545             a_third_field: eq(345),
1546         })
1547     )
1548 }
1549 
1550 #[test]
matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_followed_by_field() -> Result<()>1551 fn matches_struct_with_field_followed_by_method_taking_enum_value_param_ret_ref_followed_by_field()
1552 -> Result<()> {
1553     enum AnEnum {
1554         AVariant,
1555     }
1556 
1557     #[derive(Debug)]
1558     struct AStruct {
1559         a_field: u32,
1560         another_field: u32,
1561         a_third_field: u32,
1562     }
1563 
1564     impl AStruct {
1565         fn get_field_ref(&self, _value: AnEnum) -> &u32 {
1566             &self.a_field
1567         }
1568     }
1569 
1570     let actual = AStruct { a_field: 1, another_field: 2, a_third_field: 3 };
1571 
1572     verify_that!(
1573         actual,
1574         matches_pattern!(AStruct {
1575             another_field: eq(2),
1576             *get_field_ref(AnEnum::AVariant): eq(1),
1577             a_third_field: eq(3),
1578         })
1579     )
1580 }
1581 
1582 #[test]
matches_struct_with_a_field_followed_by_a_method_with_params_trailing_comma_ret_ref_followed_by_a_field() -> Result<()>1583 fn matches_struct_with_a_field_followed_by_a_method_with_params_trailing_comma_ret_ref_followed_by_a_field()
1584 -> Result<()> {
1585     #[derive(Debug)]
1586     struct AStruct {
1587         a_field: u32,
1588         another_field: u32,
1589         a_third_field: u32,
1590     }
1591 
1592     impl AStruct {
1593         fn get_field_ref(&self, _a: u32, _b: u32) -> &u32 {
1594             &self.a_field
1595         }
1596     }
1597 
1598     let actual = AStruct { a_field: 123, another_field: 234, a_third_field: 345 };
1599 
1600     verify_that!(
1601         actual,
1602         matches_pattern!(AStruct {
1603             another_field: eq(234),
1604             *get_field_ref(2, 3,): eq(123),
1605             a_third_field: eq(345),
1606         })
1607     )
1608 }
1609