Skip to content

Commit

Permalink
add multi embedded tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1pkg committed Apr 5, 2021
1 parent c15ac50 commit 86c5ae4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/data/embedded/file.go
Original file line number Diff line number Diff line change
@@ -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"`
}
41 changes: 40 additions & 1 deletion walkers/wast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
`),
},
},
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 86c5ae4

Please sign in to comment.