| 410 | } |
| 411 | |
| 412 | func TestParsePath(t *testing.T) { |
| 413 | tests := []struct { |
| 414 | input string |
| 415 | wantPath []string |
| 416 | wantErr bool |
| 417 | }{ |
| 418 | { |
| 419 | input: "a.b.c", |
| 420 | wantPath: []string{"a", "b", "c"}, |
| 421 | }, |
| 422 | { |
| 423 | input: "a[1][2]", |
| 424 | wantPath: []string{"a", "[1]", "[2]"}, |
| 425 | }, |
| 426 | { |
| 427 | input: "a[1][2].b", |
| 428 | wantPath: []string{"a", "[1]", "[2]", "b"}, |
| 429 | }, |
| 430 | { |
| 431 | input: `a."b.c[0]"`, |
| 432 | wantPath: []string{"a", `"b.c[0]"`}, |
| 433 | }, |
| 434 | { |
| 435 | input: `a."b.c[0]".d`, |
| 436 | wantPath: []string{"a", `"b.c[0]"`, "d"}, |
| 437 | }, |
| 438 | { |
| 439 | input: `...`, |
| 440 | }, |
| 441 | { |
| 442 | input: `.a.b.`, |
| 443 | wantPath: []string{"a", "b"}, |
| 444 | }, |
| 445 | { |
| 446 | input: `a."`, |
| 447 | wantErr: true, |
| 448 | }, |
| 449 | { |
| 450 | input: `a[`, |
| 451 | wantErr: true, |
| 452 | }, |
| 453 | { |
| 454 | input: `a[a]`, |
| 455 | wantErr: true, |
| 456 | }, |
| 457 | } |
| 458 | for i, tt := range tests { |
| 459 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 460 | path, err := sqljson.ParsePath(tt.input) |
| 461 | require.Equal(t, tt.wantPath, path) |
| 462 | require.Equal(t, tt.wantErr, err != nil) |
| 463 | }) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | func TestAppend(t *testing.T) { |
| 468 | tests := []struct { |