MCPcopy Create free account
hub / github.com/tidwall/gjson / TestQueryGetPath

Function TestQueryGetPath

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

Source from the content-addressed store, hash-verified

2442`
2443
2444func TestQueryGetPath(t *testing.T) {
2445 assert(t, strings.Join(
2446 Get(readmeJSON, "friends.#.first").Paths(readmeJSON), " ") ==
2447 "friends.0.first friends.1.first friends.2.first")
2448 assert(t, strings.Join(
2449 Get(readmeJSON, "friends.#(last=Murphy)").Paths(readmeJSON), " ") ==
2450 "")
2451 assert(t, Get(readmeJSON, "friends.#(last=Murphy)").Path(readmeJSON) ==
2452 "friends.0")
2453 assert(t, strings.Join(
2454 Get(readmeJSON, "friends.#(last=Murphy)#").Paths(readmeJSON), " ") ==
2455 "friends.0 friends.2")
2456 arr := Get(readmeJSON, "friends.#.first").Array()
2457 for i := 0; i < len(arr); i++ {
2458 assert(t, arr[i].Path(readmeJSON) == fmt.Sprintf("friends.%d.first", i))
2459 }
2460}
2461
2462func TestStaticJSON(t *testing.T) {
2463 json := `{

Callers

nothing calls this directly

Calls 5

assertFunction · 0.85
GetFunction · 0.85
PathsMethod · 0.80
PathMethod · 0.80
ArrayMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…