template

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	PkgName  string
	Mocks    []MockData
	StubImpl bool
	SyncPkg  string
}

Data is the template data used to render the Moq template.

type MethodData

type MethodData struct {
	Name    string
	Params  []ParamData
	Returns []ParamData
}

MethodData is the data which represents a method on some interface.

func (MethodData) ArgCallList

func (m MethodData) ArgCallList() string

ArgCallList is the string representation of method call parameters, ex: 's, n, foo'. In case of a last variadic parameter, it will be of the format 's, n, foos...'

func (MethodData) ArgList

func (m MethodData) ArgList() string

ArgList is the string representation of method parameters, ex: 's string, n int, foo bar.Baz'.

func (MethodData) ReturnArgNameList

func (m MethodData) ReturnArgNameList() string

ReturnArgNameList is the string representation of values being returned from the method, ex: 'foo', 's, err'.

func (MethodData) ReturnArgTypeList

func (m MethodData) ReturnArgTypeList() string

ReturnArgTypeList is the string representation of method return types, ex: 'bar.Baz', '(string, error)'.

type MockData

type MockData struct {
	InterfaceName string
	MockName      string
	Methods       []MethodData
}

MockData is the data used to generate a mock for some interface.

type ParamData

type ParamData struct {
	Name     string
	Type     string
	Pointer  bool
	Variadic bool
}

ParamData is the data which represents a parameter to some method of an interface.

func (ParamData) CallName

func (p ParamData) CallName() string

CallName returns the string representation of the parameter to be used for a method call. For a variadic paramter, it will be of the format 'foos...'.

func (ParamData) MethodArg

func (p ParamData) MethodArg() string

MethodArg is the representation of the parameter in the function signature, ex: 'name a.Type'.

func (ParamData) TypeString

func (p ParamData) TypeString() string

TypeString returns the variable type with the package qualifier in the format 'pkg.Type'.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is the Moq template. It is capable of generating the Moq implementation for the given template.Data.

func New

func New() (Template, error)

New returns a new instance of Template.

func (Template) Execute

func (t Template) Execute(w io.Writer, data Data) error

Execute generates and writes the Moq implementation for the given data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL