@@ -36,4 +36,38 @@ describe('JSONPath - Parent selector', function () {
3636 const result = jsonpath ( { json, path : 'name^^' } ) ;
3737 assert . deepEqual ( [ ] , result ) ;
3838 } ) ;
39+
40+ it ( 'select sibling via parent (with non-match present)' , ( ) => {
41+ const jsonMultipleChildren = {
42+ "name" : "root" ,
43+ "children" : [
44+ { "name" : "child1" , "children" : [ { "name" : "child1_1" } , { "name" : "child1_2" } ] } ,
45+ { "name" : "child2" , "children" : [ { "name" : "child2_1" } ] } ,
46+ { "name" : "child3" , "children" : [ { "name" : "child3_1" } , { "name" : "child3_2" } ] } ,
47+ { "name" : "child4" , "children" : [ { "name" : "child4_1" } , { "name" : "child3_1" } ] }
48+ ]
49+ } ;
50+ const expected = [ { "name" : "child3_2" } ] ;
51+ const result = jsonpath ( {
52+ json : jsonMultipleChildren ,
53+ path : '$..[?(@.name && @.name.match(/3_1$/))]^[?(@.name.match(/_2$/))]'
54+ } ) ;
55+ assert . deepEqual ( expected , result ) ;
56+ } ) ;
57+ it ( 'select sibling via parent (with multiple results)' , ( ) => {
58+ const jsonMultipleChildren = {
59+ "name" : "root" ,
60+ "children" : [
61+ { "name" : "child1" , "children" : [ { "name" : "child1_1" } , { "name" : "child1_2" } ] } ,
62+ { "name" : "child2" , "children" : [ { "name" : "child2_1" } ] } ,
63+ { "name" : "child3" , "children" : [ { "name" : "child3_1" } , { "name" : "child3_2" } , { "name" : "child3_2" , second : true } ] }
64+ ]
65+ } ;
66+ const expected = [ { "name" : "child3_2" } , { "name" : "child3_2" , second : true } ] ;
67+ const result = jsonpath ( {
68+ json : jsonMultipleChildren ,
69+ path : '$..[?(@.name && @.name.match(/3_1$/))]^[?(@.name.match(/_2$/))]'
70+ } ) ;
71+ assert . deepEqual ( expected , result ) ;
72+ } ) ;
3973} ) ;
0 commit comments