@@ -6,6 +6,8 @@ use std::path;
6
6
use predicates;
7
7
use predicates:: path:: PredicateFileContentExt ;
8
8
use predicates:: str:: PredicateStrExt ;
9
+ use predicates_core;
10
+ use predicates_tree:: CaseTreeExt ;
9
11
10
12
use fs;
11
13
@@ -15,7 +17,7 @@ use fs;
15
17
///
16
18
/// ```rust,ignore
17
19
/// use assert_fs::*;
18
- /// use predicates::*;
20
+ /// use predicates::prelude:: *;
19
21
///
20
22
/// let temp = assert_fs::TempDir::new().unwrap();
21
23
/// let input_file = temp.child("foo.txt");
@@ -30,14 +32,14 @@ pub trait PathAssert {
30
32
fn assert < I , P > ( & self , pred : I ) -> & Self
31
33
where
32
34
I : IntoPathPredicate < P > ,
33
- P : predicates :: Predicate < path:: Path > ;
35
+ P : predicates_core :: Predicate < path:: Path > ;
34
36
}
35
37
36
38
impl PathAssert for fs:: TempDir {
37
39
fn assert < I , P > ( & self , pred : I ) -> & Self
38
40
where
39
41
I : IntoPathPredicate < P > ,
40
- P : predicates :: Predicate < path:: Path > ,
42
+ P : predicates_core :: Predicate < path:: Path > ,
41
43
{
42
44
assert ( self . path ( ) , pred) ;
43
45
self
@@ -48,7 +50,7 @@ impl PathAssert for fs::ChildPath {
48
50
fn assert < I , P > ( & self , pred : I ) -> & Self
49
51
where
50
52
I : IntoPathPredicate < P > ,
51
- P : predicates :: Predicate < path:: Path > ,
53
+ P : predicates_core :: Predicate < path:: Path > ,
52
54
{
53
55
assert ( self . path ( ) , pred) ;
54
56
self
@@ -58,18 +60,18 @@ impl PathAssert for fs::ChildPath {
58
60
fn assert < I , P > ( path : & path:: Path , pred : I )
59
61
where
60
62
I : IntoPathPredicate < P > ,
61
- P : predicates :: Predicate < path:: Path > ,
63
+ P : predicates_core :: Predicate < path:: Path > ,
62
64
{
63
65
let pred = pred. into_path ( ) ;
64
- if ! pred. eval ( path) {
65
- panic ! ( "Predicate {} failed for { :?}" , pred , path) ;
66
+ if let Some ( case ) = pred. find_case ( false , & path) {
67
+ panic ! ( "Unexpected file, failed {} \n path={ :?}" , case . tree ( ) , path) ;
66
68
}
67
69
}
68
70
69
71
/// Used by `PathAssert` to convert Self into the needed `Predicate<Path>`.
70
72
pub trait IntoPathPredicate < P >
71
73
where
72
- P : predicates :: Predicate < path:: Path > ,
74
+ P : predicates_core :: Predicate < path:: Path > ,
73
75
{
74
76
/// The type of the predicate being returned.
75
77
type Predicate ;
80
82
81
83
impl < P > IntoPathPredicate < P > for P
82
84
where
83
- P : predicates :: Predicate < path:: Path > ,
85
+ P : predicates_core :: Predicate < path:: Path > ,
84
86
{
85
87
type Predicate = P ;
86
88
@@ -103,7 +105,20 @@ impl BytesContentPathPredicate {
103
105
}
104
106
}
105
107
106
- impl predicates:: Predicate < path:: Path > for BytesContentPathPredicate {
108
+ impl predicates_core:: reflection:: PredicateReflection for BytesContentPathPredicate {
109
+ fn parameters < ' a > (
110
+ & ' a self ,
111
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
112
+ self . 0 . parameters ( )
113
+ }
114
+
115
+ /// Nested `Predicate`s of the current `Predicate`.
116
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
117
+ self . 0 . children ( )
118
+ }
119
+ }
120
+
121
+ impl predicates_core:: Predicate < path:: Path > for BytesContentPathPredicate {
107
122
fn eval ( & self , item : & path:: Path ) -> bool {
108
123
self . 0 . eval ( item)
109
124
}
@@ -139,7 +154,20 @@ impl StrContentPathPredicate {
139
154
}
140
155
}
141
156
142
- impl predicates:: Predicate < path:: Path > for StrContentPathPredicate {
157
+ impl predicates_core:: reflection:: PredicateReflection for StrContentPathPredicate {
158
+ fn parameters < ' a > (
159
+ & ' a self ,
160
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
161
+ self . 0 . parameters ( )
162
+ }
163
+
164
+ /// Nested `Predicate`s of the current `Predicate`.
165
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
166
+ self . 0 . children ( )
167
+ }
168
+ }
169
+
170
+ impl predicates_core:: Predicate < path:: Path > for StrContentPathPredicate {
143
171
fn eval ( & self , item : & path:: Path ) -> bool {
144
172
self . 0 . eval ( item)
145
173
}
@@ -170,7 +198,7 @@ mod test {
170
198
fn convert_path < I , P > ( pred : I ) -> P
171
199
where
172
200
I : IntoPathPredicate < P > ,
173
- P : predicates :: Predicate < path:: Path > ,
201
+ P : predicates_core :: Predicate < path:: Path > ,
174
202
{
175
203
pred. into_path ( )
176
204
}
0 commit comments