(t *testing.T)
| 560 | } |
| 561 | |
| 562 | func TestGetByTraversal(t *testing.T) { |
| 563 | type C struct { |
| 564 | C0 int |
| 565 | C1 int |
| 566 | } |
| 567 | type B struct { |
| 568 | B0 string |
| 569 | B1 *C |
| 570 | } |
| 571 | type A struct { |
| 572 | A0 int |
| 573 | A1 B |
| 574 | } |
| 575 | |
| 576 | testCases := []struct { |
| 577 | Index []int |
| 578 | ExpectedName string |
| 579 | ExpectNil bool |
| 580 | }{ |
| 581 | { |
| 582 | Index: []int{0}, |
| 583 | ExpectedName: "A0", |
| 584 | }, |
| 585 | { |
| 586 | Index: []int{1, 0}, |
| 587 | ExpectedName: "B0", |
| 588 | }, |
| 589 | { |
| 590 | Index: []int{1, 1, 1}, |
| 591 | ExpectedName: "C1", |
| 592 | }, |
| 593 | { |
| 594 | Index: []int{3, 4, 5}, |
| 595 | ExpectNil: true, |
| 596 | }, |
| 597 | { |
| 598 | Index: []int{}, |
| 599 | ExpectNil: true, |
| 600 | }, |
| 601 | { |
| 602 | Index: nil, |
| 603 | ExpectNil: true, |
| 604 | }, |
| 605 | } |
| 606 | |
| 607 | m := NewMapperFunc("db", func(n string) string { return n }) |
| 608 | tm := m.TypeMap(reflect.TypeOf(A{})) |
| 609 | |
| 610 | for i, tc := range testCases { |
| 611 | fi := tm.GetByTraversal(tc.Index) |
| 612 | if tc.ExpectNil { |
| 613 | if fi != nil { |
| 614 | t.Errorf("%d: expected nil, got %v", i, fi) |
| 615 | } |
| 616 | continue |
| 617 | } |
| 618 | |
| 619 | if fi == nil { |
nothing calls this directly
no test coverage detected