Skip to content

Commit 38c17a8

Browse files
authored
Merge pull request #52 from innoave/feat/not-expectation-combinator
feat: implement `Not` expectation combinator and revise failure messages
2 parents 0d1a1a7 + eedf13a commit 38c17a8

40 files changed

Lines changed: 1508 additions & 931 deletions

File tree

src/bigdecimal/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn verify_bigdecimal_is_equal_to_other_fails() {
2727
assert_eq!(
2828
failures,
2929
&[
30-
r"assertion failed: expected subject is equal to BigDecimal(sign=Minus, scale=3, digits=[42831])
30+
r"assertion failed: expected subject to be equal to BigDecimal(sign=Minus, scale=3, digits=[42831])
3131
but was: BigDecimal(sign=Plus, scale=3, digits=[42831])
3232
expected: BigDecimal(sign=Minus, scale=3, digits=[42831])
3333
"
@@ -181,7 +181,7 @@ fn verify_bigdecimalref_is_equal_to_other_fails() {
181181
assert_eq!(
182182
failures,
183183
&[
184-
r"assertion failed: expected subject is equal to BigDecimalRef { sign: Minus, digits: 42831, scale: 3 }
184+
r"assertion failed: expected subject to be equal to BigDecimalRef { sign: Minus, digits: 42831, scale: 3 }
185185
but was: BigDecimalRef { sign: Plus, digits: 42831, scale: 3 }
186186
expected: BigDecimalRef { sign: Minus, digits: 42831, scale: 3 }
187187
"

src/boolean/mod.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::assertions::AssertBoolean;
44
use crate::colored::{mark_missing, mark_unexpected};
55
use crate::expectations::{IsFalse, IsTrue};
6-
use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Spec};
6+
use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec};
77
use crate::std::format;
88
use crate::std::string::String;
99

@@ -25,30 +25,46 @@ impl Expectation<bool> for IsTrue {
2525
*subject
2626
}
2727

28-
fn message(&self, expression: &Expression<'_>, actual: &bool, format: &DiffFormat) -> String {
29-
let marked_actual = mark_unexpected(actual, format);
30-
let marked_expected = mark_missing(&true, format);
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);
3137
format!(
32-
"expected {expression} is {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
38+
"expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
3339
true
3440
)
3541
}
3642
}
3743

44+
impl Invertible for IsTrue {}
45+
3846
impl Expectation<bool> for IsFalse {
3947
fn test(&mut self, subject: &bool) -> bool {
4048
!*subject
4149
}
4250

43-
fn message(&self, expression: &Expression<'_>, actual: &bool, format: &DiffFormat) -> String {
51+
fn message(
52+
&self,
53+
expression: &Expression<'_>,
54+
actual: &bool,
55+
inverted: bool,
56+
format: &DiffFormat,
57+
) -> String {
4458
let marked_actual = mark_unexpected(actual, format);
45-
let marked_expected = mark_missing(&false, format);
59+
let marked_expected = mark_missing(&inverted, format);
4660
format!(
47-
"expected {expression} is {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
61+
"expected {expression} to be {:?}\n but was: {marked_actual}\n expected: {marked_expected}",
4862
false
4963
)
5064
}
5165
}
5266

67+
impl Invertible for IsFalse {}
68+
5369
#[cfg(test)]
5470
mod tests;

src/boolean/tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ fn verify_bool_is_not_equal_to_false_fails() {
2323

2424
assert_eq!(
2525
failures,
26-
&[r"assertion failed: expected my_thing is not equal to false
26+
&[
27+
r"assertion failed: expected my_thing to be not equal to false
2728
but was: false
2829
expected: not false
29-
"]
30+
"
31+
]
3032
);
3133
}
3234

@@ -47,7 +49,7 @@ fn verify_bool_is_true_fails() {
4749
.named("my_thing")
4850
.is_true()
4951
.display_failures(),
50-
&[r"assertion failed: expected my_thing is true
52+
&[r"assertion failed: expected my_thing to be true
5153
but was: false
5254
expected: true
5355
"]
@@ -63,7 +65,7 @@ fn verify_bool_is_false_fails() {
6365

6466
assert_eq!(
6567
failures,
66-
&[r"assertion failed: expected my_thing is false
68+
&[r"assertion failed: expected my_thing to be false
6769
but was: true
6870
expected: false
6971
"]
@@ -83,7 +85,7 @@ mod colored {
8385

8486
assert_eq!(
8587
failures,
86-
&["assertion failed: expected subject is true\n \
88+
&["assertion failed: expected subject to be true\n \
8789
but was: \u{1b}[31mfalse\u{1b}[0m\n \
8890
expected: \u{1b}[32mtrue\u{1b}[0m\n\
8991
"]
@@ -99,7 +101,7 @@ mod colored {
99101

100102
assert_eq!(
101103
failures,
102-
&["assertion failed: expected subject is false\n \
104+
&["assertion failed: expected subject to be false\n \
103105
but was: \u{1b}[31mtrue\u{1b}[0m\n \
104106
expected: \u{1b}[33mfalse\u{1b}[0m\n\
105107
"]

0 commit comments

Comments
 (0)