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
#[cfg(feature = "float")]
pub mod precision;
use self::fluid::core::prelude::*;
use crate as fluid;
use std::ops::Not;
#[derive(Debug, Drop)]
pub struct BeEqualTo<L: Debug, R: Debug>
where
L: PartialEq<R>,
{
should: ShouldImpl<L>,
right: R,
}
impl<L: Debug, R: Debug> AssertionImpl for BeEqualTo<L, R>
where
L: PartialEq<R>,
{
type Left = L;
fn failure_message(&mut self) -> Option<String> {
let left_dbg = self.should.left_dbg();
let right_dbg = self.right.dbg().to_string();
let truthness = self.should.truthness();
if (self.should.left.as_ref()? == &self.right) != truthness {
let message = if let Some(stringified) = self.should.stringified() {
if left_dbg != right_dbg {
format!(
"\t{} has the value {}.\n\
\tIt should{} be equal to {} but it is{}.",
stringified,
left_dbg,
truthness.str(),
right_dbg,
truthness.not().str()
)
} else {
format!(
"\t{} is equal to {}\n\
\tbut it should{}.",
stringified,
left_dbg,
truthness.str()
)
}
} else {
format!(
"\t{} is{} equal to {}.",
left_dbg,
truthness.not().str(),
right_dbg
)
};
Some(message)
} else {
None
}
}
fn consume_as_should(mut self) -> ShouldImpl<Self::Left> {
self.should.take()
}
fn should_mut(&mut self) -> &mut ShouldImpl<Self::Left> {
&mut self.should
}
}
impl<L: Debug> Should<L> {
pub fn be_equal_to<R: Debug>(self, right: R) -> ChainableAssert<BeEqualTo<L, R>>
where
L: PartialEq<R>,
{
let implem = BeEqualTo {
should: self.into(),
right,
};
ChainableAssert(implem)
}
}