33use crate :: assertions:: AssertBoolean ;
44use crate :: colored:: { mark_missing, mark_unexpected} ;
55use crate :: expectations:: { IsFalse , IsTrue } ;
6- use crate :: spec:: { DiffFormat , Expectation , Expression , FailingStrategy , Spec } ;
6+ use crate :: spec:: { DiffFormat , Expectation , Expression , FailingStrategy , Invertible , Spec } ;
77use crate :: std:: format;
88use 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+
3846impl 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) ]
5470mod tests;
0 commit comments