@@ -108,6 +108,22 @@ def test_fields_value(self):
108108 jsonpath .auto_id_field = 'id'
109109 self .check_cases ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 , '@' ])) ])
110110
111+ def test_root_value (self ):
112+ jsonpath .auto_id_field = None
113+ self .check_cases ([
114+ ('$' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
115+ ('foo.$' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
116+ ('foo.$.foo' , {'foo' : 'baz' }, ['baz' ]),
117+ ])
118+
119+ def test_this_value (self ):
120+ jsonpath .auto_id_field = None
121+ self .check_cases ([
122+ ('@' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
123+ ('foo.@' , {'foo' : 'baz' }, ['baz' ]),
124+ (
'[email protected] ' , {
'foo' : {
'baz' :
3 }}, [
3 ]),
125+ ])
126+
111127 def test_index_value (self ):
112128 self .check_cases ([
113129 ('[0]' , [42 ], [42 ]),
@@ -167,6 +183,22 @@ def test_fields_paths(self):
167183 jsonpath .auto_id_field = 'id'
168184 self .check_paths ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set (['foo' , 'baz' , 'id' ])) ])
169185
186+ def test_root_paths (self ):
187+ jsonpath .auto_id_field = None
188+ self .check_paths ([
189+ ('$' , {'foo' : 'baz' }, ['$' ]),
190+ ('foo.$' , {'foo' : 'baz' }, ['$' ]),
191+ ('foo.$.foo' , {'foo' : 'baz' }, ['foo' ]),
192+ ])
193+
194+ def test_this_paths (self ):
195+ jsonpath .auto_id_field = None
196+ self .check_paths ([
197+ ('@' , {'foo' : 'baz' }, ['@' ]),
198+ ('foo.@' , {'foo' : 'baz' }, ['foo' ]),
199+ (
'[email protected] ' , {
'foo' : {
'baz' :
3 }}, [
'foo.baz' ]),
200+ ])
201+
170202 def test_index_paths (self ):
171203 self .check_paths ([('[0]' , [42 ], ['[0]' ]),
172204 ('[2]' , [34 , 65 , 29 , 59 ], ['[2]' ])])
@@ -197,6 +229,22 @@ def test_fields_auto_id(self):
197229 'baz' : 2 },
198230 set (['1' , 'baz' ])) ])
199231
232+ def test_root_auto_id (self ):
233+ jsonpath .auto_id_field = 'id'
234+ self .check_cases ([
235+ ('$.id' , {'foo' : 'baz' }, ['$' ]), # This is a wonky case that is not that interesting
236+ ('foo.$.id' , {'foo' : 'baz' , 'id' : 'bizzle' }, ['bizzle' ]),
237+ ('foo.$.baz.id' , {'foo' : 4 , 'baz' : 3 }, ['baz' ]),
238+ ])
239+
240+ def test_this_auto_id (self ):
241+ jsonpath .auto_id_field = 'id'
242+ self .check_cases ([
243+ ('id' , {'foo' : 'baz' }, ['@' ]), # This is, again, a wonky case that is not that interesting
244+ (
'[email protected] ' , {
'foo' :
'baz' }, [
'foo' ]),
245+ (
'[email protected] ' , {
'foo' : {
'baz' :
3 }}, [
'foo.baz' ]),
246+ ])
247+
200248 def test_index_auto_id (self ):
201249 jsonpath .auto_id_field = "id"
202250 self .check_cases ([('[0].id' , [42 ], ['[0]' ]),
0 commit comments