============================================================================= Get family — empty key component resolves to KeyPathNotFoundError (SYS-REQ-016) ============================================================================= Verifies: SYS-REQ-016 [boundary] An empty-string path component
(t *testing.T)
| 38 | // An empty-string path component is not a resolvable object key or array index; |
| 39 | // Get must surface KeyPathNotFoundError rather than panicking. |
| 40 | func TestGetEmptyKeyPathComponent(t *testing.T) { |
| 41 | cases := []struct { |
| 42 | name string |
| 43 | data string |
| 44 | keys []string |
| 45 | }{ |
| 46 | {name: "empty component on array root", data: `[1,2,3]`, keys: []string{""}}, |
| 47 | {name: "empty component on object root", data: `{"a":1}`, keys: []string{""}}, |
| 48 | {name: "empty component after valid key", data: `{"a":[1]}`, keys: []string{"a", ""}}, |
| 49 | {name: "empty component before valid key", data: `{"a":1}`, keys: []string{"", "a"}}, |
| 50 | {name: "two empty components", data: `{"a":1}`, keys: []string{"", ""}}, |
| 51 | } |
| 52 | for _, tc := range cases { |
| 53 | t.Run(tc.name, func(t *testing.T) { |
| 54 | var ( |
| 55 | val []byte |
| 56 | dt ValueType |
| 57 | off int |
| 58 | err error |
| 59 | ) |
| 60 | runNoPanic(t, tc.name, func() { |
| 61 | val, dt, off, err = Get([]byte(tc.data), tc.keys...) |
| 62 | }) |
| 63 | if !errors.Is(err, KeyPathNotFoundError) { |
| 64 | t.Fatalf("Get(%q,%v) err = %v, want KeyPathNotFoundError", tc.data, tc.keys, err) |
| 65 | } |
| 66 | if dt != NotExist { |
| 67 | t.Fatalf("Get(%q,%v) type = %v, want NotExist", tc.data, tc.keys, dt) |
| 68 | } |
| 69 | if off != -1 { |
| 70 | t.Fatalf("Get(%q,%v) offset = %d, want -1", tc.data, tc.keys, off) |
| 71 | } |
| 72 | if val != nil { |
| 73 | t.Fatalf("Get(%q,%v) value = %v, want nil", tc.data, tc.keys, val) |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Verifies: SYS-REQ-016 [boundary] |
| 80 | // Typed Get accessors must propagate KeyPathNotFoundError for an empty key |
nothing calls this directly
no test coverage detected