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

Function testEachKeyPathDepth

issues_56_107_229_test.go:101–139  ·  view source on GitHub ↗
(t *testing.T, depth int)

Source from the content-addressed store, hash-verified

99}
100
101func testEachKeyPathDepth(t *testing.T, depth int) {
102 t.Helper()
103 path := make([]string, depth)
104 var data strings.Builder
105 for i := range path {
106 path[i] = "key" + strconv.Itoa(i)
107 data.WriteString(`{"`)
108 data.WriteString(path[i])
109 data.WriteString(`":`)
110 }
111 data.WriteString(`"found"`)
112 for range path {
113 data.WriteByte('}')
114 }
115
116 callbacks := 0
117 offset := EachKey([]byte(data.String()), func(idx int, value []byte, valueType ValueType, err error) {
118 callbacks++
119 if err != nil {
120 t.Errorf("EachKey callback returned error: %v", err)
121 }
122 if idx != 0 {
123 t.Errorf("EachKey callback index = %d; want 0", idx)
124 }
125 if valueType != String {
126 t.Errorf("EachKey value type = %v; want %v", valueType, String)
127 }
128 if string(value) != "found" {
129 t.Errorf("EachKey value = %q; want %q", value, "found")
130 }
131 }, path)
132
133 if offset < 0 {
134 t.Fatalf("EachKey did not find the %d-component path", depth)
135 }
136 if callbacks != 1 {
137 t.Fatalf("EachKey callbacks = %d; want 1", callbacks)
138 }
139}
140
141// Verifies: SYS-REQ-009 (Set)
142// reqproof:proptest:skip targeted witness/regression test; not a property-test subject

Calls 2

EachKeyFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected