easy_assert/
bool_assertions.rs

1//! ## Usage
2//!
3//! ``` rust
4//! use easy_assert::bool_assertions::BooleanAssert;
5//!
6//! #[test]
7//! pub fn true_is_true() {
8//!     BooleanAssert::assert_that(true).is_true();
9//! }
10//!
11//! #[test]
12//! pub fn false_is_false() {
13//!     BooleanAssert::assert_that(false).is_false();
14//! }
15//! ```
16
17use crate::assertions::BooleanCheck;
18use crate::test_failed;
19
20pub struct BooleanAssert {
21    actual: bool,
22}
23
24impl BooleanAssert {
25    pub fn assert_that(actual: bool) -> BooleanAssert {
26        BooleanAssert { actual }
27    }
28
29    pub fn is_true(&self) {
30        BooleanCheck::is_true(self);
31    }
32
33    pub fn is_false(&self) {
34        BooleanCheck::is_false(self);
35    }
36}
37
38impl BooleanCheck for BooleanAssert {
39    fn is_true(&self) {
40        if !self.actual {
41            let error_message = format!("Actual is: {}, but should be TRUE", self.actual);
42            test_failed(&error_message);
43        }
44    }
45
46    fn is_false(&self) {
47        if self.actual {
48            let error_message = format!("Actual is: {}, but should be FALSE", self.actual);
49            test_failed(&error_message);
50        }
51    }
52}