diff --git a/package/moq/moq.go b/package/moq/moq.go index ea8d71a..83c5551 100644 --- a/package/moq/moq.go +++ b/package/moq/moq.go @@ -132,12 +132,11 @@ func (m *Mocker) extractArgs(sig *types.Signature, list *types.Tuple, nameFormat } typename := types.TypeString(p.Type(), m.packageQualifier) // check for final variadic argument - if sig.Variadic() && ii == listLen-1 && typename[0:2] == "[]" { - typename = "..." + typename[2:] - } + variadic := sig.Variadic() && ii == listLen-1 && typename[0:2] == "[]" param := ¶m{ - Name: name, - Type: typename, + Name: name, + Type: typename, + Variadic: variadic, } params = append(params, param) } @@ -165,7 +164,7 @@ func (m *method) Arglist() string { func (m *method) ArgCallList() string { params := make([]string, len(m.Params)) for i, p := range m.Params { - params[i] = p.Name + params[i] = p.CallName() } return strings.Join(params, ", ") } @@ -182,15 +181,26 @@ func (m *method) ReturnArglist() string { } type param struct { - Name string - Type string + Name string + Type string + Variadic bool } func (p param) String() string { return fmt.Sprintf("%s %s", p.Name, p.TypeString()) } +func (p param) CallName() string { + if p.Variadic { + return p.Name + "..." + } + return p.Name +} + func (p param) TypeString() string { + if p.Variadic { + return "..." + p.Type[2:] + } return p.Type } diff --git a/package/moq/moq_test.go b/package/moq/moq_test.go index 2b85c3a..e69d4aa 100644 --- a/package/moq/moq_test.go +++ b/package/moq/moq_test.go @@ -79,6 +79,7 @@ func TestVariadicArguments(t *testing.T) { "package variadic", "type GreeterMock struct", "GreetFunc func(ctx context.Context, names ...string) string", + "return mock.GreetFunc(ctx, names...)", } for _, str := range strs { if !strings.Contains(s, str) {