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() iiface := iface.Type().Underlying().(*types.Interface).Complete()
obj := &obj{ obj := &obj{
Name: n, InterfaceName: n,
} }
for i := 0; i < iiface.NumMethods(); i++ { for i := 0; i < iiface.NumMethods(); i++ {
meth := iiface.Method(i) meth := iiface.Method(i)
@ -105,7 +105,7 @@ func extractArgs(list *types.Tuple, nameFormat string) []*param {
} }
type obj struct { type obj struct {
Name string InterfaceName string
Methods []*method Methods []*method
} }
type method struct { type method struct {
@ -159,31 +159,31 @@ package todo
// AUTOGENERATED BY MOQ // AUTOGENERATED BY MOQ
// github.com/matryer/moq // github.com/matryer/moq
{{ range .Objs }} {{ range $i, $obj := .Objs }}
// {{.Name}}Mock is a mock implementation of {{.Name}}. // {{.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}} // // make and configure a mocked {{.InterfaceName}}
// mocked{{.Name}} := {{.Name}}Mock{ // mocked{{.InterfaceName}} := &{{.InterfaceName}}Mock{ {{ range .Methods }}
// {{ range .Methods }}{{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} { // {{.Name}}Func: func({{ .Arglist }}) {{.ReturnArglist}} {
// panic("TODO: mock out the {{.Name}} function") // 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 { type {{.InterfaceName}}Mock struct {
{{ range .Methods }} {{- range .Methods }}
// {{.Name}}Func mocks the {{.Name}} function. // {{.Name}}Func mocks the {{.Name}} function.
{{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}} {{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}}
{{ end }}} {{- end }}
}
{{ range .Methods }} {{ range .Methods }}
// {{.Name}} calls the mocked {{.Name}}Func function or panics if it was // {{.Name}} calls {{.Name}}Func.
// not set. func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist}} {
func (mock {{.Name}}Mock) {{.Name}}({{ .Arglist }}) {{.ReturnArglist}} {
if mock.{{.Name}} == nil { if mock.{{.Name}} == nil {
panic("moq: {{.Name}}Func is nil but was just called") panic("moq: {{.Name}}Func is nil but was just called")
} }