github.com/mailru/activerecord@v1.12.2/internal/pkg/parser/partialstruct_test.go (about) 1 package parser 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/mailru/activerecord/internal/pkg/ds" 8 ) 9 10 type Foo struct { 11 Bar int 12 } 13 14 func TestParsePartialStructFields(t *testing.T) { 15 type args struct { 16 dst *ds.RecordPackage 17 name string 18 pkgName string 19 path string 20 } 21 22 dst := ds.NewRecordPackage() 23 24 if _, err := dst.AddImport("github.com/mailru/activerecord/internal/pkg/parser"); err != nil { 25 t.Errorf("can't prepare test data: %s", err) 26 return 27 } 28 29 tests := []struct { 30 name string 31 args args 32 want []ds.PartialFieldDeclaration 33 wantErr bool 34 }{ 35 { 36 name: "parse fields of parser.Foo struct", 37 args: args{ 38 dst: dst, 39 name: "Foo", 40 pkgName: "parser", 41 path: ".", 42 }, 43 want: []ds.PartialFieldDeclaration{ 44 {Name: "Bar", Type: "int"}, 45 }, 46 wantErr: false, 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 got, err := ParsePartialStructFields(tt.args.dst, tt.args.name, tt.args.pkgName, tt.args.path) 52 if (err != nil) != tt.wantErr { 53 t.Errorf("ParsePartialStructFields() error = %v, wantErr %v", err, tt.wantErr) 54 return 55 } 56 if !reflect.DeepEqual(got, tt.want) { 57 t.Errorf("ParsePartialStructFields() got = %v, want %v", got, tt.want) 58 } 59 }) 60 } 61 }