MCPcopy
hub / github.com/tidwall/gjson / TestIndexesMatchesRaw

Function TestIndexesMatchesRaw

gjson_test.go:2278–2294  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2276}
2277
2278func TestIndexesMatchesRaw(t *testing.T) {
2279 var exampleJSON = `{
2280 "objectArray":[
2281 {"first": "Jason", "age": 41},
2282 {"first": "Dale", "age": 44},
2283 {"first": "Roger", "age": 68},
2284 {"first": "Mandy", "age": 32}
2285 ]
2286 }`
2287 r := Get(exampleJSON, `objectArray.#(age>43)#.first`)
2288 assert(t, len(r.Indexes) == 2)
2289 assert(t, Parse(exampleJSON[r.Indexes[0]:]).String() == "Dale")
2290 assert(t, Parse(exampleJSON[r.Indexes[1]:]).String() == "Roger")
2291 r = Get(exampleJSON, `objectArray.#(age>43)#`)
2292 assert(t, Parse(exampleJSON[r.Indexes[0]:]).Get("first").String() == "Dale")
2293 assert(t, Parse(exampleJSON[r.Indexes[1]:]).Get("first").String() == "Roger")
2294}
2295
2296func TestIssue240(t *testing.T) {
2297 nonArrayData := `{"jsonrpc":"2.0","method":"subscription","params":

Callers

nothing calls this directly

Calls 5

GetFunction · 0.85
assertFunction · 0.85
ParseFunction · 0.85
GetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…