Verifies: SYS-REQ-010 [regression, issues #209 and #141]
(t *testing.T)
| 72 | |
| 73 | // Verifies: SYS-REQ-010 [regression, issues #209 and #141] |
| 74 | func 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] |
| 103 | func TestEachKeyDescendsIntoArrayIndexAtEndOfPath(t *testing.T) { |
nothing calls this directly
no test coverage detected