@@ -2167,32 +2167,20 @@ func TestIndexes(t *testing.T) {
21672167 }
21682168}
21692169
2170- func TestHashtagIndexesMatchesRaw (t * testing.T ) {
2170+ func TestIndexesMatchesRaw (t * testing.T ) {
21712171 var exampleJSON = `{
21722172 "objectArray":[
2173+ {"first": "Jason", "age": 41},
21732174 {"first": "Dale", "age": 44},
21742175 {"first": "Roger", "age": 68},
2176+ {"first": "Mandy", "age": 32}
21752177 ]
21762178 }`
21772179 r := Get (exampleJSON , `objectArray.#(age>43)#.first` )
2178- all := Get (exampleJSON , `@this` )
2179- all .ForEach (func (_ , value Result ) bool {
2180- if value .IsArray () {
2181- value .ForEach (func (_ , v Result ) bool {
2182- if v .IsArray () {
2183- v .ForEach (func (_ , sv Result ) bool {
2184- if sv .IsObject () {
2185- assert (t , string (exampleJSON [r .Indexes [0 ]:r .Indexes [0 ]+ len (sv .Raw )]) == sv .Raw )
2186- }
2187- if sv .IsArray () {
2188- assert (t , string (exampleJSON [r .Indexes [1 ]:r .Indexes [1 ]+ len (sv .Raw )]) == sv .Raw )
2189- }
2190- return true
2191- })
2192- }
2193- return true
2194- })
2195- }
2196- return true
2197- })
2180+ assert (t , len (r .Indexes ) == 2 )
2181+ assert (t , Parse (exampleJSON [r .Indexes [0 ]:]).String () == "Dale" )
2182+ assert (t , Parse (exampleJSON [r .Indexes [1 ]:]).String () == "Roger" )
2183+ r = Get (exampleJSON , `objectArray.#(age>43)#` )
2184+ assert (t , Parse (exampleJSON [r .Indexes [0 ]:]).Get ("first" ).String () == "Dale" )
2185+ assert (t , Parse (exampleJSON [r .Indexes [1 ]:]).Get ("first" ).String () == "Roger" )
21982186}
0 commit comments