MCPcopy Create free account
hub / github.com/buger/jsonparser / TestEachKeyDescendsIntoArrayIndexAtEndOfPath

Function TestEachKeyDescendsIntoArrayIndexAtEndOfPath

v131_regression_test.go:103–132  ·  view source on GitHub ↗

Verifies: SYS-REQ-008 [regression, issue #232]

(t *testing.T)

Source from the content-addressed store, hash-verified

101
102// Verifies: SYS-REQ-008 [regression, issue #232]
103func TestEachKeyDescendsIntoArrayIndexAtEndOfPath(t *testing.T) {
104 data := []byte(`{"request":{"headers":{"User-Agent":["abc"]}}}`)
105 path := []string{"request", "headers", "User-Agent", "[0]"}
106
107 getValue, getType, _, err := Get(data, path...)
108 if err != nil {
109 t.Fatalf("Get returned error: %v", err)
110 }
111
112 callbacks := 0
113 EachKey(data, func(idx int, value []byte, valueType ValueType, err error) {
114 callbacks++
115 if err != nil {
116 t.Errorf("EachKey callback returned error: %v", err)
117 }
118 if idx != 0 {
119 t.Errorf("EachKey callback index = %d, want 0", idx)
120 }
121 if !bytes.Equal(value, getValue) {
122 t.Errorf("EachKey value = %q, want Get value %q", value, getValue)
123 }
124 if valueType != getType {
125 t.Errorf("EachKey type = %v, want Get type %v", valueType, getType)
126 }
127 }, path)
128
129 if callbacks != 1 {
130 t.Fatalf("EachKey callback count = %d, want 1", callbacks)
131 }
132}

Callers

nothing calls this directly

Calls 2

GetFunction · 0.85
EachKeyFunction · 0.85

Tested by

no test coverage detected