improvements

This commit is contained in:
Mat Ryer 2016-08-29 13:20:37 +01:00
parent 124baf32f3
commit 67ac3093f9

View File

@ -63,7 +63,7 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
}
iiface := iface.Type().Underlying().(*types.Interface).Complete()
obj := &obj{
Name: n,
InterfaceName: n,
}
for i := 0; i < iiface.NumMethods(); i++ {
meth := iiface.Method(i)
@ -105,8 +105,8 @@ func extractArgs(list *types.Tuple, nameFormat string) []*param {
}
type obj struct {
Name string
Methods []*method
InterfaceName string
Methods []*method
}
type method struct {
Name string
@ -159,35 +159,35 @@ package todo
// AUTOGENERATED BY MOQ
// github.com/matryer/moq
{{ range .Objs }}
// {{.Name}}Mock is a mock implementation of {{.Name}}.
{{ range $i, $obj := .Objs }}
// {{.InterfaceName}}Mock is a mock implementation of {{.InterfaceName}}
// generated by github.com/matryer/moq.
//
// func TestSomethingThatUses{{.Name}}(t *testing.T) {
// func TestSomethingThatUses{{.InterfaceName}}(t *testing.T) {
//
// // make and configure a mocked {{.Name}}
// mocked{{.Name}} := {{.Name}}Mock{
// {{ range .Methods }}{{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} {
// // make and configure a mocked {{.InterfaceName}}
// mocked{{.InterfaceName}} := &{{.InterfaceName}}Mock{ {{ range .Methods }}
// {{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} {
// panic("TODO: mock out the {{.Name}} function")
// },
// {{end}}
// },{{- end }}
// }
//
// // TODO: use mocked{{.Name}} in code that requires {{.Name}}
// // TODO: use mocked{{.InterfaceName}} in code that requires {{.InterfaceName}}
//
// }
type {{.Name}}Mock struct {
{{ range .Methods }}
type {{.InterfaceName}}Mock struct {
{{- range .Methods }}
// {{.Name}}Func mocks the {{.Name}} function.
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
{{ end }}}
{{- end }}
}
{{ range .Methods }}
// {{.Name}} calls the mocked {{.Name}}Func function or panics if it was
// not set.
func (mock {{.Name}}Mock) {{.Name}}({{ .Arglist }}) {{.ReturnArglist}} {
// {{.Name}} calls {{.Name}}Func.
func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} {
if mock.{{.Name}} == nil {
panic("moq: {{.Name}}Func is nil but was just called")
}
return mock.{{.Name}}Func({{ .ArgCallList }})
return mock.{{.Name}}Func({{.ArgCallList}})
}
{{ end }}
{{ end }}