Minor update to test

This commit is contained in:
tidwall 2021-09-01 07:24:15 -07:00
parent 160fb9d6a1
commit 44b8c19d87
1 changed files with 9 additions and 21 deletions

View File

@ -2167,32 +2167,20 @@ func TestIndexes(t *testing.T) {
} }
} }
func TestHashtagIndexesMatchesRaw(t *testing.T) { func TestIndexesMatchesRaw(t *testing.T) {
var exampleJSON = `{ var exampleJSON = `{
"objectArray":[ "objectArray":[
{"first": "Jason", "age": 41},
{"first": "Dale", "age": 44}, {"first": "Dale", "age": 44},
{"first": "Roger", "age": 68}, {"first": "Roger", "age": 68},
{"first": "Mandy", "age": 32}
] ]
}` }`
r := Get(exampleJSON, `objectArray.#(age>43)#.first`) r := Get(exampleJSON, `objectArray.#(age>43)#.first`)
all := Get(exampleJSON, `@this`) assert(t, len(r.Indexes) == 2)
all.ForEach(func(_, value Result) bool { assert(t, Parse(exampleJSON[r.Indexes[0]:]).String() == "Dale")
if value.IsArray() { assert(t, Parse(exampleJSON[r.Indexes[1]:]).String() == "Roger")
value.ForEach(func(_, v Result) bool { r = Get(exampleJSON, `objectArray.#(age>43)#`)
if v.IsArray() { assert(t, Parse(exampleJSON[r.Indexes[0]:]).Get("first").String() == "Dale")
v.ForEach(func(_, sv Result) bool { assert(t, Parse(exampleJSON[r.Indexes[1]:]).Get("first").String() == "Roger")
if sv.IsObject() {
assert(t, string(exampleJSON[r.Indexes[0]:r.Indexes[0]+len(sv.Raw)]) == sv.Raw)
}
if sv.IsArray() {
assert(t, string(exampleJSON[r.Indexes[1]:r.Indexes[1]+len(sv.Raw)]) == sv.Raw)
}
return true
})
}
return true
})
}
return true
})
} }