fixed call list bug
This commit is contained in:
parent
edc3a126a0
commit
5933d55c69
@ -132,12 +132,11 @@ func (m *Mocker) extractArgs(sig *types.Signature, list *types.Tuple, nameFormat
|
|||||||
}
|
}
|
||||||
typename := types.TypeString(p.Type(), m.packageQualifier)
|
typename := types.TypeString(p.Type(), m.packageQualifier)
|
||||||
// check for final variadic argument
|
// check for final variadic argument
|
||||||
if sig.Variadic() && ii == listLen-1 && typename[0:2] == "[]" {
|
variadic := sig.Variadic() && ii == listLen-1 && typename[0:2] == "[]"
|
||||||
typename = "..." + typename[2:]
|
|
||||||
}
|
|
||||||
param := ¶m{
|
param := ¶m{
|
||||||
Name: name,
|
Name: name,
|
||||||
Type: typename,
|
Type: typename,
|
||||||
|
Variadic: variadic,
|
||||||
}
|
}
|
||||||
params = append(params, param)
|
params = append(params, param)
|
||||||
}
|
}
|
||||||
@ -165,7 +164,7 @@ func (m *method) Arglist() string {
|
|||||||
func (m *method) ArgCallList() string {
|
func (m *method) ArgCallList() string {
|
||||||
params := make([]string, len(m.Params))
|
params := make([]string, len(m.Params))
|
||||||
for i, p := range m.Params {
|
for i, p := range m.Params {
|
||||||
params[i] = p.Name
|
params[i] = p.CallName()
|
||||||
}
|
}
|
||||||
return strings.Join(params, ", ")
|
return strings.Join(params, ", ")
|
||||||
}
|
}
|
||||||
@ -184,13 +183,24 @@ func (m *method) ReturnArglist() string {
|
|||||||
type param struct {
|
type param struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
|
Variadic bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p param) String() string {
|
func (p param) String() string {
|
||||||
return fmt.Sprintf("%s %s", p.Name, p.TypeString())
|
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 {
|
func (p param) TypeString() string {
|
||||||
|
if p.Variadic {
|
||||||
|
return "..." + p.Type[2:]
|
||||||
|
}
|
||||||
return p.Type
|
return p.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ func TestVariadicArguments(t *testing.T) {
|
|||||||
"package variadic",
|
"package variadic",
|
||||||
"type GreeterMock struct",
|
"type GreeterMock struct",
|
||||||
"GreetFunc func(ctx context.Context, names ...string) string",
|
"GreetFunc func(ctx context.Context, names ...string) string",
|
||||||
|
"return mock.GreetFunc(ctx, names...)",
|
||||||
}
|
}
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
if !strings.Contains(s, str) {
|
if !strings.Contains(s, str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user