1
+ use self :: errors:: * ;
2
+ pub use self :: errors:: { Error , ErrorKind } ;
3
+ use diff;
4
+ use difference:: Changeset ;
1
5
use std:: fmt;
2
6
use std:: process;
3
7
use std:: rc;
4
8
5
- use difference:: Changeset ;
6
-
7
- use diff;
8
- use self :: errors:: * ;
9
- pub use self :: errors:: { Error , ErrorKind } ;
10
-
11
9
12
10
#[ derive( Clone , PartialEq , Eq ) ]
13
11
pub enum Content {
@@ -24,15 +22,13 @@ impl fmt::Debug for Content {
24
22
}
25
23
}
26
24
27
- impl < ' a > From < & ' a str > for Content
28
- {
25
+ impl < ' a > From < & ' a str > for Content {
29
26
fn from ( data : & ' a str ) -> Self {
30
27
Content :: Str ( data. into ( ) )
31
28
}
32
29
}
33
30
34
- impl < ' a > From < & ' a [ u8 ] > for Content
35
- {
31
+ impl < ' a > From < & ' a [ u8 ] > for Content {
36
32
fn from ( data : & ' a [ u8 ] ) -> Self {
37
33
Content :: Bytes ( data. into ( ) )
38
34
}
@@ -47,7 +43,9 @@ struct IsPredicate {
47
43
impl IsPredicate {
48
44
pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
49
45
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
+ }
51
49
Content :: Bytes ( ref expect) => self . verify_bytes ( expect, got) ,
52
50
}
53
51
}
@@ -97,7 +95,9 @@ struct ContainsPredicate {
97
95
}
98
96
99
97
fn 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)
101
101
}
102
102
103
103
#[ test]
@@ -109,7 +109,9 @@ fn test_find_subsequence() {
109
109
impl ContainsPredicate {
110
110
pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
111
111
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
+ }
113
115
Content :: Bytes ( ref expect) => self . verify_bytes ( expect, got) ,
114
116
}
115
117
}
@@ -157,8 +159,9 @@ impl FnPredicate {
157
159
pub fn verify ( & self , got : & [ u8 ] ) -> Result < ( ) > {
158
160
let got = String :: from_utf8_lossy ( got) ;
159
161
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) ;
162
165
}
163
166
164
167
Ok ( ( ) )
@@ -175,7 +178,7 @@ impl fmt::Debug for FnPredicate {
175
178
enum ContentPredicate {
176
179
Is ( IsPredicate ) ,
177
180
Contains ( ContainsPredicate ) ,
178
- Fn ( FnPredicate ) ,
181
+ Fn ( FnPredicate ) ,
179
182
}
180
183
181
184
impl ContentPredicate {
@@ -287,8 +290,9 @@ impl Output {
287
290
/// .unwrap();
288
291
/// ```
289
292
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 > ,
292
296
{
293
297
let pred = FnPredicate {
294
298
pred : rc:: Rc :: new ( pred) ,
@@ -329,10 +333,7 @@ pub struct OutputPredicate {
329
333
330
334
impl OutputPredicate {
331
335
pub fn new ( kind : OutputKind , pred : Output ) -> Self {
332
- Self {
333
- kind,
334
- pred,
335
- }
336
+ Self { kind, pred }
336
337
}
337
338
338
339
pub ( crate ) fn verify ( & self , got : & process:: Output ) -> Result < ( ) > {
0 commit comments