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
use core::{Matcher, Join};
pub struct BeTrue;
pub fn be_true() -> BeTrue {
BeTrue
}
impl Matcher<bool, ()> for BeTrue {
fn failure_message(&self, join: Join, _: &bool) -> String {
format!("expected {} be true", join)
}
fn matches(&self, actual: &bool) -> bool {
*actual
}
}
pub struct BeFalse;
pub fn be_false() -> BeFalse {
BeFalse
}
impl Matcher<bool, ()> for BeFalse {
fn failure_message(&self, join: Join, _: &bool) -> String {
format!("expected {} be false", join)
}
fn matches(&self, actual: &bool) -> bool {
!*actual
}
}
#[cfg(test)]
mod tests {
use super::{be_true, be_false};
use core::expect;
#[test]
fn test_be_true_message() {
expect(1 == 0)
.to(be_true())
.assert_eq_message("expected to be true");
}
#[test]
fn test_not_to_be_true_message() {
expect(0 == 0)
.not_to(be_true())
.assert_eq_message("expected not to be true");
}
#[test]
fn test_be_false_message() {
expect(0 == 0)
.to(be_false())
.assert_eq_message("expected to be false");
}
#[test]
fn test_not_to_be_false_message() {
expect(0 == 1)
.not_to(be_false())
.assert_eq_message("expected not to be false")
}
}