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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use ;
use ArgMatcher;
;
/// Returns an equality matcher.
///
/// Returns a matcher that compares `Arg` using equality across
/// borrows.
///
/// Unlike [`eq_against`], it only allows equality matching for the
/// same type. This comes at the benefit of being able to match across
/// borrows.
///
/// # Examples
///
/// ## Basic usage
///
/// ```
/// use faux::matcher::{self, ArgMatcher};
///
/// let eq_four = matcher::eq(4);
/// assert!(eq_four.matches(&4));
/// assert!(!eq_four.matches(&5));
/// ```
///
/// ## Matching across borrows
///
/// ```
/// use std::rc::Rc;
/// use faux::matcher::{self, ArgMatcher};
///
/// // `Rc<T>` implements `Borrow<T>`
/// assert!(matcher::eq(5).matches(&Rc::new(5)));
///
/// // `&T` implements `Borrow<T>`
/// let ref_of_ref: &&i32 = &&5;
/// assert!(matcher::eq(5).matches(ref_of_ref));
/// ```
///
/// ## Usage within when!
///
/// For convenience, [`faux::when!`](crate::when!) defaults to the
/// `eq` matcher. See the [matcher
/// syntax](../macro.when.html#argument-matchers) for more
/// information.
///
/// ```ignore
/// // `_` means the `any` matcher
/// faux::when!(my_struct.some_method(2)).then_return(5);
///
/// // we can also call it manually within `when!`
/// faux::when!(my_struct.some_method(_ = faux::matcher::eq(2)))
/// .then_return(5);
///
/// // or call it manually outside `when!`
/// faux::when!(my_struct.some_method)
/// .with_args((matcher::eq(2),)).then_return(5);
/// ```
;
/// Returns an equality matcher for [different types].
///
/// Unlike [`eq`], it matches even if the types are different. This,
/// however, comes at the cost of not being able to match across
/// borrows.
///
/// # Examples
///
/// ```
/// use faux::matcher::{self, ArgMatcher};
///
/// // `String` implements `PartialEq<&str>`
/// assert!(matcher::eq_against("x".to_string()).matches(&"x"));
/// assert!(!matcher::eq_against("x".to_string()).matches(&"y"));
/// ```
///
/// ## Usage within when!
///
/// [`faux::when!`](crate::when!) does not have a special syntax for
/// this matcher. See the [matcher
/// syntax](../macro.when.html#argument-matchers) for more
/// information.
///
/// ```ignore
/// // we can call it within `when!`
/// faux::when!(my_struct.some_method(_ = faux::matcher::eq_against(2)))
/// .then_return(5);
///
/// // or call it outside `when!`
/// faux::when!(my_struct.some_method)
/// .with_args((matcher::eq_against(2),)).then_return(5);
/// ```
///
/// [different types]:
/// https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#how-can-i-compare-two-different-types