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

Function TestDeleteDoesNotAliasInputBackingArray

v131_regression_test.go:74–100  ·  view source on GitHub ↗

Verifies: SYS-REQ-010 [regression, issues #209 and #141]

(t *testing.T)

Source from the content-addressed store, hash-verified

72
73// Verifies: SYS-REQ-010 [regression, issues #209 and #141]
74func TestDeleteDoesNotAliasInputBackingArray(t *testing.T) {
75 t.Run("delete existing key", func(t *testing.T) {
76 input, snapshot := inputWithSpareCapacity(`{"a":1,"b":2}`)
77
78 result := Delete(input, "a")
79 if got, want := string(result), `{"b":2}`; got != want {
80 t.Fatalf("Delete result = %s, want %s", got, want)
81 }
82 assertBackingArrayUnchanged(t, input, snapshot)
83
84 result[0] ^= 0xff
85 assertBackingArrayUnchanged(t, input, snapshot)
86 })
87
88 t.Run("delete root with empty path", func(t *testing.T) {
89 input, snapshot := inputWithSpareCapacity(`{"a":1}`)
90
91 result := Delete(input)
92 if len(result) != 0 {
93 t.Fatalf("Delete result = %q, want an empty document", result)
94 }
95 assertBackingArrayUnchanged(t, input, snapshot)
96
97 result = append(result, 'x')
98 assertBackingArrayUnchanged(t, input, snapshot)
99 })
100}
101
102// Verifies: SYS-REQ-008 [regression, issue #232]
103func TestEachKeyDescendsIntoArrayIndexAtEndOfPath(t *testing.T) {

Callers

nothing calls this directly

Calls 3

inputWithSpareCapacityFunction · 0.85
DeleteFunction · 0.85

Tested by

no test coverage detected