Documentation ¶
Index ¶
- type CalledExpr
- type CalledMethod
- type Func
- func (f *Func) Fields(fs *token.FileSet) []string
- func (f *Func) FindCalledMethods() (fns []*CalledExpr)
- func (f *Func) HasMockableField(fields []ReceiverField) bool
- func (f *Func) HasReceiverFields() bool
- func (f *Func) IsMethod() bool
- func (f *Func) IsVariadic() bool
- func (f *Func) LastParam() *ast.Field
- func (f *Func) LastResult() *ast.Field
- func (f *Func) Name() string
- func (f *Func) NumParams() int
- func (f *Func) NumResults() int
- func (f *Func) Params(fs *token.FileSet) []string
- func (f *Func) ParamsNames() []string
- func (f *Func) ParseFieldsToNodeString(fs *token.FileSet, ident *ast.Ident, fields []*ast.Field, field *ast.Field, ...) (nodeString string)
- func (f *Func) ParseStarExprToReceiverField(se *ast.StarExpr) []ReceiverField
- func (f *Func) ReceiverFields() []ReceiverField
- func (f *Func) ReceiverInstance() string
- func (f *Func) ReceiverType() ast.Expr
- func (f *Func) Results(fs *token.FileSet) []string
- func (f *Func) ResultsNames() []string
- func (f *Func) ReturnsError() bool
- func (f *Func) TestName() string
- type Generator
- type Options
- type ReceiverField
- func (r *ReceiverField) IsFieldMockable() bool
- func (r *ReceiverField) IsIdentMockable(ident *ast.Ident) bool
- func (r *ReceiverField) IsNameCalled() bool
- func (r *ReceiverField) IsSelectorExprMockable(expr *ast.SelectorExpr) bool
- func (r *ReceiverField) Set()
- func (r *ReceiverField) SetForArray(typ ast.Expr)
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CalledExpr ¶
CalledExpr is a extension of `ast.CallExpr`
func (*CalledExpr) FieldName ¶
func (c *CalledExpr) FieldName() string
FieldName returns the filed name of the `CalledExpr` in the struct receiver
func (*CalledExpr) GetArgsReturns ¶
func (c *CalledExpr) GetArgsReturns() (args, returns []string, err error)
GetArgsReturns return the args and result of the `CalledExpr`
func (*CalledExpr) ParseIntfToArgsAndReturns ¶
func (c *CalledExpr) ParseIntfToArgsAndReturns(itf *types.Interface, fnName string) (args, returns []string)
type CalledMethod ¶
type Func ¶
type Func struct { PkgDecls []ast.Decl File *ast.File Struct *ast.StructType Signature *ast.FuncDecl PkgPath string }
Func is a wrapper around ast.FuncDecl containing few methods to use within a test template
func NewFunc ¶
func NewFunc( sig *ast.FuncDecl, str *ast.StructType, file *ast.File, pkgDecls []ast.Decl, pkgPath string) *Func
NewFunc returns pointer to the Func struct
func (*Func) FindCalledMethods ¶
func (f *Func) FindCalledMethods() (fns []*CalledExpr)
FindCalledMethods find all called method inside the function body
func (*Func) HasMockableField ¶
func (f *Func) HasMockableField(fields []ReceiverField) bool
func (*Func) HasReceiverFields ¶
func (*Func) IsVariadic ¶
IsVariadic returns true if it's the variadic function
func (*Func) LastResult ¶
LastResult returns function's last result
func (*Func) NumResults ¶
NumResults returns a number of the function results
func (*Func) ParamsNames ¶
ParamsNames returns a list of the function params' names
func (*Func) ParseFieldsToNodeString ¶
func (*Func) ParseStarExprToReceiverField ¶
func (f *Func) ParseStarExprToReceiverField(se *ast.StarExpr) []ReceiverField
func (*Func) ReceiverFields ¶
func (f *Func) ReceiverFields() []ReceiverField
func (*Func) ReceiverInstance ¶
ReceiverInstance returns a instance of the method receiver
func (*Func) ReceiverType ¶
ReceiverType returns a type of the method receiver
func (*Func) Results ¶
Results returns a list of the function results with their types if function's last param is an error it is not included in the result slice
func (*Func) ResultsNames ¶
ResultsNames returns a list of the function results' names if function's last result is an error the name of param is "err"
func (*Func) ReturnsError ¶
ReturnsError returns true if the function's last param's type is error
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is used to generate a test stub for function Func
func NewGenerator ¶
NewGenerator returns a pointer to Generator
func (*Generator) WriteHeader ¶
WriteHeader writes a package name and import specs
type ReceiverField ¶
type ReceiverField struct { CalledMethods []*CalledExpr Field *ast.Field PkgPath string Name string StructName string Mockable bool IsCalled bool }
func NewReceiverField ¶
func NewReceiverField( name, pkgPath string, fd *ast.Field, calledMethods []*CalledExpr, ) ReceiverField
func (*ReceiverField) IsFieldMockable ¶
func (r *ReceiverField) IsFieldMockable() bool
func (*ReceiverField) IsIdentMockable ¶
func (r *ReceiverField) IsIdentMockable(ident *ast.Ident) bool
func (*ReceiverField) IsNameCalled ¶
func (r *ReceiverField) IsNameCalled() bool
func (*ReceiverField) IsSelectorExprMockable ¶
func (r *ReceiverField) IsSelectorExprMockable(expr *ast.SelectorExpr) bool
func (*ReceiverField) Set ¶
func (r *ReceiverField) Set()
func (*ReceiverField) SetForArray ¶
func (r *ReceiverField) SetForArray(typ ast.Expr)
type TemplateData ¶
type TemplateData struct { Comment string Func *Func CalledMethods []CalledMethod }