Skip to content

Commit

Permalink
Merge pull request #82 from zcolleen/master
Browse files Browse the repository at this point in the history
Method ParamPtrsStruct added for minimock
  • Loading branch information
hexdigest authored Apr 20, 2024
2 parents 70b5239 + bfc6a4a commit 8143058
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions generator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ func (m Method) ParamsStruct() string {
return "struct{\n" + strings.Join(ss, "\n ") + "}"
}

// ParamPtrsStruct returns a struct type with pointer fields corresponding
// to the method params
func (m Method) ParamPtrsStruct() string {
ss := []string{}
for _, p := range m.Params {
if p.Variadic {
ss = append(ss, p.Name+" *"+strings.Replace(p.Type, "...", "[]", 1))
} else {
ss = append(ss, p.Name+" *"+p.Type)
}
}
return "struct{\n" + strings.Join(ss, "\n ") + "}"
}

// ResultsStruct returns a struct type with fields corresponding
// to the method results
func (m Method) ResultsStruct() string {
Expand Down
8 changes: 8 additions & 0 deletions generator/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func TestMethod_ParamsStruct(t *testing.T) {
assert.Equal(t, "struct{\ns []string}", m.ParamsStruct())
}

func TestMethod_ParamPtrsStruct(t *testing.T) {
m := Method{
Name: "method",
Params: []Param{{Name: "s", Type: "...string", Variadic: true}},
}
assert.Equal(t, "struct{\ns *[]string}", m.ParamPtrsStruct())
}

func TestMethod_ResultsStruct(t *testing.T) {
m := Method{
Name: "method",
Expand Down

0 comments on commit 8143058

Please sign in to comment.