diff --git a/tests/data/embedded/file.go b/tests/data/embedded/file.go new file mode 100644 index 0000000..781d76f --- /dev/null +++ b/tests/data/embedded/file.go @@ -0,0 +1,25 @@ +//+build tests_data + +package embedded + +import "time" + +type MetaLabaratory struct { +} + +type Person struct { + Birtday time.Time `json:"birthday" db:"birthday"` + Weight float64 `json:"weight" db:"weight"` + Height float64 `json:"height" db:"height"` +} + +type PatientObject struct { + MetaLabaratory + Person + ID string `json:"id" db:"id"` + Enrolled bool `json:"enrolled" db:"enrolled"` + Gender string `json:"gender" db:"gender"` + PhoneNumber *string `json:"phone_number" db:"phone_number"` + Email *string `json:"email" db:"email"` + AddressTitle *string `json:"address_title" db:"address_title"` +} diff --git a/walkers/wast_test.go b/walkers/wast_test.go index 497c51b..35874cf 100644 --- a/walkers/wast_test.go +++ b/walkers/wast_test.go @@ -344,6 +344,45 @@ type ( d2 float64 d3 string ) +`), + }, + }, + "embedded structs pkg should visit all expected levels structs without deep": { + ctx: context.Background(), + r: regexp.MustCompile(`.*`), + p: data.NewParser("embedded"), + a: astutil.UFFN, + sp: astutil.Package{}, + w: data.Writer{Writer: &mocks.Writer{}}, + stg: pck, + bref: true, + sts: map[string][]byte{ + "tests_data_embedded_file.go": []byte(` +//+build tests_data + +package embedded + +import "time" + +type MetaLabaratory struct { +} + +type Person struct { + Birtday time.Time 'json:"birthday" db:"birthday"' + Weight float64 'json:"weight" db:"weight"' + Height float64 'json:"height" db:"height"' +} + +type PatientObject struct { + Person + ID string 'json:"id" db:"id"' + Gender string 'json:"gender" db:"gender"' + PhoneNumber *string 'json:"phone_number" db:"phone_number"' + Email *string 'json:"email" db:"email"' + AddressTitle *string 'json:"address_title" db:"address_title"' + Enrolled bool 'json:"enrolled" db:"enrolled"' + MetaLabaratory +} `), }, }, @@ -377,7 +416,7 @@ type ( } // format actual and expected identically actual := strings.Trim(buf.String(), "\n") - expected := strings.Trim(string(st), "\n") + expected := strings.ReplaceAll(strings.Trim(string(st), "\n"), "'", "`") if !reflect.DeepEqual(actual, expected) { t.Errorf("id %v actual %v doesn't equal to expected %v", id, actual, expected) }