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
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 == true
}
}
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 == false
}
}
#[cfg(test)]
mod tests {
use super::{be_true, be_false};
use core::{Matcher, Join};
#[test]
fn test_be_true() {
assert!(be_true().matches(&true));
}
#[test]
fn test_be_true_message() {
let m = be_true().failure_message(Join::To, &false);
assert!(m == "expected to be true");
}
#[test]
#[should_panic]
fn test_be_true_should_panic() {
assert!(be_true().matches(&false));
}
#[test]
fn test_be_false() {
assert!(be_false().matches(&false));
}
#[test]
fn test_be_false_message() {
let m = be_false().failure_message(Join::To, &true);
assert!(m == "expected to be false");
}
#[test]
#[should_panic]
fn test_be_false_should_panic() {
assert!(be_false().matches(&true));
}
}