-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
70 lines (60 loc) · 1.75 KB
/
Copy pathmod.rs
File metadata and controls
70 lines (60 loc) · 1.75 KB
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
//! Implementation of assertions for values of type `bool`.
use crate::assertions::AssertBoolean;
use crate::colored::{mark_missing, mark_unexpected};
use crate::expectations::{IsFalse, IsTrue, is_false, is_true};
use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec};
use crate::std::format;
use crate::std::string::String;
impl<R> AssertBoolean for Spec<'_, bool, R>
where
R: FailingStrategy,
{
fn is_true(self) -> Self {
self.expecting(is_true())
}
fn is_false(self) -> Self {
self.expecting(is_false())
}
}
impl Expectation<bool> for IsTrue {
fn test(&mut self, subject: &bool) -> bool {
*subject
}
fn message(
&self,
expression: &Expression<'_>,
actual: &bool,
inverted: bool,
format: &DiffFormat,
) -> String {
let marked_actual = mark_unexpected(&actual, format);
let marked_expected = mark_missing(&!inverted, format);
format!(
"expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
true
)
}
}
impl Invertible for IsTrue {}
impl Expectation<bool> for IsFalse {
fn test(&mut self, subject: &bool) -> bool {
!*subject
}
fn message(
&self,
expression: &Expression<'_>,
actual: &bool,
inverted: bool,
format: &DiffFormat,
) -> String {
let marked_actual = mark_unexpected(actual, format);
let marked_expected = mark_missing(&inverted, format);
format!(
"expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
false
)
}
}
impl Invertible for IsFalse {}
#[cfg(test)]
mod tests;