This repository was archived by the owner on Feb 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -33,10 +33,10 @@ pub struct WildcardedChild {}
33
33
34
34
impl Matcher for WildcardedChild {
35
35
fn select < ' a > ( & self , node : & ' a Value ) -> Iter < ' a > {
36
- if let Some ( m ) = node. as_object ( ) {
37
- Box :: new ( m. values ( ) )
38
- } else {
39
- Box :: new ( iter:: empty ( ) )
36
+ match node {
37
+ Value :: Object ( m ) => Box :: new ( m. values ( ) ) ,
38
+ Value :: Array ( a ) => Box :: new ( a . iter ( ) ) ,
39
+ _ => Box :: new ( iter:: empty ( ) ) ,
40
40
}
41
41
}
42
42
}
@@ -75,3 +75,25 @@ impl Matcher for Union {
75
75
Box :: new ( self . elements . iter ( ) . flat_map ( move |it| it. select ( node) ) )
76
76
}
77
77
}
78
+
79
+ #[ cfg( test) ]
80
+ mod tests {
81
+ use super :: * ;
82
+ use serde_json:: { json, Value } ;
83
+
84
+ #[ test]
85
+ fn object_wildcard ( ) {
86
+ let s = WildcardedChild { } ;
87
+ let j = json ! ( { "a" : 1 , "b" : 2 } ) ;
88
+ let r: Vec < & Value > = s. select ( & j) . collect ( ) ;
89
+ assert_eq ! ( format!( "{:?}" , r) , "[Number(1), Number(2)]" ) ;
90
+ }
91
+
92
+ #[ test]
93
+ fn array_wildcard ( ) {
94
+ let s = WildcardedChild { } ;
95
+ let j = json ! ( [ 1 , 2 ] ) ;
96
+ let r: Vec < & Value > = s. select ( & j) . collect ( ) ;
97
+ assert_eq ! ( format!( "{:?}" , r) , "[Number(1), Number(2)]" ) ;
98
+ }
99
+ }
Original file line number Diff line number Diff line change 37
37
"name" : " wildcarded child of array" ,
38
38
"selector" : " $.*" ,
39
39
"document" : [" first" , " second" ],
40
- "result" : []
40
+ "result" : [" first " , " second " ]
41
41
}, {
42
42
"name" : " wildcarded child dot child" ,
43
43
"selector" : " $.*.a" ,
You can’t perform that action at this time.
0 commit comments