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

Function TestSetArrayIndexUnderObjectMalformedJSON_KI3

set_spec_test.go:81–107  ·  view source on GitHub ↗

TestSetArrayIndexUnderObjectMalformedJSON_KI3 is the class witness for the failure mode tracked as KnownIssue KI-3 / DEFECT-260726-MFPA. Historically, when Set received a key path whose [N] component addressed an OBJECT-typed parent, the output was malformed JSON (encoding/json rejected it) while Se

(t *testing.T)

Source from the content-addressed store, hash-verified

79//
80// Reproduces: KI-3 (fixed)
81func TestSetArrayIndexUnderObjectMalformedJSON_KI3(t *testing.T) {
82 cases := []struct {
83 name string
84 in string
85 keys []string
86 }{
87 {"array_index_under_object_nested", `{"a":{"b":1}}`, []string{"a", "[5]"}},
88 {"array_index_under_object_deeper", `{"a":{"b":1}}`, []string{"a", "[0]", "x"}},
89 {"array_index_under_object_root", `{"a":1}`, []string{"[0]"}},
90 {"empty_brackets_under_object_root", `{"a":1}`, []string{"[]"}},
91 {"empty_brackets_after_object_key", `{"a":{"b":1}}`, []string{"a", "[]"}},
92 {"empty_brackets_after_array_idx", `{"a":[{"":0}]}`, []string{"a", "[0]", "[]"}},
93 }
94 for _, c := range cases {
95 t.Run(c.name, func(t *testing.T) {
96 out, err := Set([]byte(c.in), []byte(`9`), c.keys...)
97 if err != nil {
98 t.Fatalf("KI-3 Set(%s,%v) returned error after fix: %v", c.in, c.keys, err)
99 }
100 // KI-3 fix invariant: the returned bytes MUST be valid JSON.
101 if !json.Valid(out) {
102 t.Fatalf("KI-3 regressed: Set(%s,%v) -> %s (invalid JSON)", c.in, c.keys, string(out))
103 }
104 t.Logf("KI-3 fixed: Set(%s,%v) -> %s (valid JSON)", c.in, c.keys, string(out))
105 })
106 }
107}
108
109// TestSetAutoCoerce_KI3 locks the auto-coerce semantics that fix KI-3. When a
110// path component expects one container type but the existing structure is the

Callers

nothing calls this directly

Calls 1

SetFunction · 0.85

Tested by

no test coverage detected