(t *testing.T)
| 186 | } |
| 187 | |
| 188 | func TestParseJSONPath(t *testing.T) { |
| 189 | tests := []struct { |
| 190 | name string |
| 191 | path string |
| 192 | expected []PathSegment |
| 193 | }{ |
| 194 | { |
| 195 | name: "empty path", |
| 196 | path: "", |
| 197 | expected: []PathSegment{}, |
| 198 | }, |
| 199 | { |
| 200 | name: "root path", |
| 201 | path: "/", |
| 202 | expected: []PathSegment{}, |
| 203 | }, |
| 204 | { |
| 205 | name: "simple key", |
| 206 | path: "/name", |
| 207 | expected: []PathSegment{ |
| 208 | {Type: "key", Value: "name"}, |
| 209 | }, |
| 210 | }, |
| 211 | { |
| 212 | name: "array index", |
| 213 | path: "/tools/0", |
| 214 | expected: []PathSegment{ |
| 215 | {Type: "key", Value: "tools"}, |
| 216 | {Type: "index", Value: "0", Index: 0}, |
| 217 | }, |
| 218 | }, |
| 219 | { |
| 220 | name: "complex path", |
| 221 | path: "/tools/1/permissions/read", |
| 222 | expected: []PathSegment{ |
| 223 | {Type: "key", Value: "tools"}, |
| 224 | {Type: "index", Value: "1", Index: 1}, |
| 225 | {Type: "key", Value: "permissions"}, |
| 226 | {Type: "key", Value: "read"}, |
| 227 | }, |
| 228 | }, |
| 229 | } |
| 230 | |
| 231 | for _, tt := range tests { |
| 232 | t.Run(tt.name, func(t *testing.T) { |
| 233 | result := parseJSONPath(tt.path) |
| 234 | |
| 235 | if len(result) != len(tt.expected) { |
| 236 | t.Errorf("Expected %d segments, got %d", len(tt.expected), len(result)) |
| 237 | return |
| 238 | } |
| 239 | |
| 240 | for i, expected := range tt.expected { |
| 241 | if result[i].Type != expected.Type { |
| 242 | t.Errorf("Segment %d: expected Type=%s, got Type=%s", i, expected.Type, result[i].Type) |
| 243 | } |
| 244 | if result[i].Value != expected.Value { |
| 245 | t.Errorf("Segment %d: expected Value=%s, got Value=%s", i, expected.Value, result[i].Value) |
nothing calls this directly
no test coverage detected