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

Function TestSetEmptyKeyPathComponent

empty_key_path_test.go:179–207  ·  view source on GitHub ↗

============================================================================= Set — empty key component produces a defined document, no panic (SYS-REQ-009) ============================================================================= Verifies: SYS-REQ-009 [boundary] Set with an empty-string key comp

(t *testing.T)

Source from the content-addressed store, hash-verified

177// createInsertComponent / calcAllocateSpace. The empty key is treated as an
178// object property name (not an array index) and produces a defined document.
179func TestSetEmptyKeyPathComponent(t *testing.T) {
180 cases := []struct {
181 name string
182 data string
183 setData string
184 keys []string
185 }{
186 {name: "single empty key on empty object", data: `{}`, setData: `"v"`, keys: []string{""}},
187 {name: "single empty key on populated object", data: `{"a":1}`, setData: `"v"`, keys: []string{""}},
188 {name: "empty key leading", data: `{}`, setData: `"v"`, keys: []string{"", "a"}},
189 }
190 for _, tc := range cases {
191 t.Run(tc.name, func(t *testing.T) {
192 var (
193 val []byte
194 err error
195 )
196 runNoPanic(t, tc.name, func() {
197 val, err = Set([]byte(tc.data), []byte(tc.setData), tc.keys...)
198 })
199 if err != nil {
200 t.Fatalf("Set(%q,%q,%v) returned unexpected error: %v", tc.data, tc.setData, tc.keys, err)
201 }
202 if val == nil {
203 t.Fatalf("Set(%q,%q,%v) returned nil document", tc.data, tc.setData, tc.keys)
204 }
205 })
206 }
207}
208
209// =============================================================================
210// Delete — empty key component leaves the payload unchanged, no panic

Callers

nothing calls this directly

Calls 2

runNoPanicFunction · 0.85
SetFunction · 0.85

Tested by

no test coverage detected