1+ use self :: errors:: * ;
2+ pub use self :: errors:: { Error , ErrorKind } ;
3+ use diff;
4+ use difference:: Changeset ;
15use std:: fmt;
26use std:: process;
37use std:: rc;
48
5- use difference:: Changeset ;
6-
7- use diff;
8- use self :: errors:: * ;
9- pub use self :: errors:: { Error , ErrorKind } ;
10-
119
1210#[ derive( Clone , PartialEq , Eq ) ]
1311pub enum Content {
@@ -24,15 +22,13 @@ impl fmt::Debug for Content {
2422 }
2523}
2624
27- impl < ' a > From < & ' a str > for Content
28- {
25+ impl < ' a > From < & ' a str > for Content {
2926 fn from ( data : & ' a str ) -> Self {
3027 Content :: Str ( data. into ( ) )
3128 }
3229}
3330
34- impl < ' a > From < & ' a [ u8 ] > for Content
35- {
31+ impl < ' a > From < & ' a [ u8 ] > for Content {
3632 fn from ( data : & ' a [ u8 ] ) -> Self {
3733 Content :: Bytes ( data. into ( ) )
3834 }
@@ -47,7 +43,9 @@ struct IsPredicate {
4743impl IsPredicate {
4844 pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
4945 match self . expect {
50- Content :: Str ( ref expect) => self . verify_str ( expect, String :: from_utf8_lossy ( got) . as_ref ( ) ) ,
46+ Content :: Str ( ref expect) => {
47+ self . verify_str ( expect, String :: from_utf8_lossy ( got) . as_ref ( ) )
48+ }
5149 Content :: Bytes ( ref expect) => self . verify_bytes ( expect, got) ,
5250 }
5351 }
@@ -97,7 +95,9 @@ struct ContainsPredicate {
9795}
9896
9997fn find_subsequence ( haystack : & [ u8 ] , needle : & [ u8 ] ) -> Option < usize > {
100- haystack. windows ( needle. len ( ) ) . position ( |window| window == needle)
98+ haystack
99+ . windows ( needle. len ( ) )
100+ . position ( |window| window == needle)
101101}
102102
103103#[ test]
@@ -109,7 +109,9 @@ fn test_find_subsequence() {
109109impl ContainsPredicate {
110110 pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
111111 match self . expect {
112- Content :: Str ( ref expect) => self . verify_str ( expect, String :: from_utf8_lossy ( got) . as_ref ( ) ) ,
112+ Content :: Str ( ref expect) => {
113+ self . verify_str ( expect, String :: from_utf8_lossy ( got) . as_ref ( ) )
114+ }
113115 Content :: Bytes ( ref expect) => self . verify_bytes ( expect, got) ,
114116 }
115117 }
@@ -157,8 +159,9 @@ impl FnPredicate {
157159 pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
158160 let got = String :: from_utf8_lossy ( got) ;
159161 let pred = & self . pred ;
160- if ! pred ( & got) {
161- bail ! ( ErrorKind :: PredicateFailed ( got. into_owned( ) , self . msg. clone( ) ) ) ;
162+ if !pred ( & got) {
163+ let err: Error = ErrorKind :: PredicateFailed ( got. into_owned ( ) , self . msg . clone ( ) ) . into ( ) ;
164+ bail ! ( err) ;
162165 }
163166
164167 Ok ( ( ) )
@@ -175,7 +178,7 @@ impl fmt::Debug for FnPredicate {
175178enum ContentPredicate {
176179 Is ( IsPredicate ) ,
177180 Contains ( ContainsPredicate ) ,
178- Fn ( FnPredicate ) ,
181+ Fn ( FnPredicate ) ,
179182}
180183
181184impl ContentPredicate {
@@ -287,8 +290,9 @@ impl Output {
287290 /// .unwrap();
288291 /// ```
289292 pub fn satisfies < F , M > ( pred : F , msg : M ) -> Self
290- where F : ' static + Fn ( & str ) -> bool ,
291- M : Into < String >
293+ where
294+ F : ' static + Fn ( & str ) -> bool ,
295+ M : Into < String > ,
292296 {
293297 let pred = FnPredicate {
294298 pred : rc:: Rc :: new ( pred) ,
@@ -329,10 +333,7 @@ pub struct OutputPredicate {
329333
330334impl OutputPredicate {
331335 pub fn new ( kind : OutputKind , pred : Output ) -> Self {
332- Self {
333- kind,
334- pred,
335- }
336+ Self { kind, pred }
336337 }
337338
338339 pub ( crate ) fn verify ( & self , got : & process:: Output ) -> Result < ( ) > {
0 commit comments