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
pub enum Matcher<I> {
Val(I),
Any,
}
impl<I: std::fmt::Debug> std::fmt::Debug for Matcher<I> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Val(val) => write!(f, "{:?}", val),
Self::Any => write!(f, "Any"),
}
}
}
impl<I: PartialEq> PartialEq for Matcher<I> {
fn eq(&self, other: &Matcher<I>) -> bool {
use crate::matcher::Matcher::*;
match (self, other) {
(&Val(ref a), &Val(ref b)) => a == b,
_ => true,
}
}
}
pub fn eq<I>(input: I) -> Matcher<I> {
Matcher::Val(input)
}
pub fn any<I>() -> Matcher<I> {
Matcher::Any
}
#[cfg(test)]
mod test {
use super::Matcher::*;
use table_test::table_test;
#[test]
fn test_eq() {
let table = vec![
((Val(5), Val(6)), false),
((Val(5), Val(5)), true),
((Any, Val(5)), true),
((Val(5), Any), true),
((Any, Any), true),
];
for (test_case, (matcher_1, matcher_2), expected) in table_test!(table) {
let actual = matcher_1.eq(&matcher_2);
test_case
.given(&format!("{:?}, {:?}", matcher_1, matcher_2))
.when("equal")
.then(&format!("is {}", expected))
.assert_eq(expected, actual);
}
}
}