1use crate::assertions::AssertBoolean;
4use crate::colored::{mark_missing, mark_unexpected};
5use crate::expectations::{is_false, is_true, IsFalse, IsTrue};
6use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec};
7use crate::std::format;
8use crate::std::string::String;
9
10impl<R> AssertBoolean for Spec<'_, bool, R>
11where
12 R: FailingStrategy,
13{
14 fn is_true(self) -> Self {
15 self.expecting(is_true())
16 }
17
18 fn is_false(self) -> Self {
19 self.expecting(is_false())
20 }
21}
22
23impl Expectation<bool> for IsTrue {
24 fn test(&mut self, subject: &bool) -> bool {
25 *subject
26 }
27
28 fn message(
29 &self,
30 expression: &Expression<'_>,
31 actual: &bool,
32 inverted: bool,
33 format: &DiffFormat,
34 ) -> String {
35 let marked_actual = mark_unexpected(&actual, format);
36 let marked_expected = mark_missing(&!inverted, format);
37 format!(
38 "expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
39 true
40 )
41 }
42}
43
44impl Invertible for IsTrue {}
45
46impl Expectation<bool> for IsFalse {
47 fn test(&mut self, subject: &bool) -> bool {
48 !*subject
49 }
50
51 fn message(
52 &self,
53 expression: &Expression<'_>,
54 actual: &bool,
55 inverted: bool,
56 format: &DiffFormat,
57 ) -> String {
58 let marked_actual = mark_unexpected(actual, format);
59 let marked_expected = mark_missing(&inverted, format);
60 format!(
61 "expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
62 false
63 )
64 }
65}
66
67impl Invertible for IsFalse {}
68
69#[cfg(test)]
70mod tests;