Skip to content

Commit

Permalink
feat(generate): accept []interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1v3r committed Jan 18, 2022
1 parent 12a358b commit bb8de83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/check/checktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ func (m *InterfaceMethod) GetTestResultParamInTmpl() string {
func testParamToString(params []parser.Param) string {
var res []string
for i, param := range params {
tmplString := fmt.Sprintf("tt.Input.Args[%d].(%s)", i, param.Type)
res = append(res, tmplString)
// TODO manage array and pointer
typ := param.Type
if param.IsArray {
typ = "[]" + typ
}
if param.IsPointer {
typ = "*" + typ
}
res = append(res, fmt.Sprintf("tt.Input.Args[%d].(%s)", i, typ))
}
return strings.Join(res, ",")
}
Expand Down
3 changes: 3 additions & 0 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ func (p *Param) astGetEltType(expr ast.Expr) string {
case *ast.StarExpr:
p.IsPointer = true
p.astGetEltType(v.X)
case *ast.InterfaceType:
p.Type = "interface{}"
default:
log.Fatalf("unknow param type: %+v", v)
}
return p.Type
}

func (p *Param) astGetPackageName(expr ast.Expr) {
switch v := expr.(type) {
case *ast.Ident:
Expand Down

0 comments on commit bb8de83

Please sign in to comment.