Documentation ¶
Overview ¶
Package model contains the data model necessary for generating mock implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrorInterface = Interface{ Name: "error", Methods: []*Method{ { Name: "Error", Out: []*Parameter{ { Name: "", Type: PredeclaredType("string"), }, }, }, }, }
ErrorInterface represent built-in error interface.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
Interface is a Go interface.
func InterfaceFromInterfaceType ¶
InterfaceFromInterfaceType returns a pointer to an interface for the given reflection interface type.
func (*Interface) AddMethod ¶ added in v1.7.1
AddMethod adds a new method, de-duplicating by method name.
func (*Interface) TypeParamIndexByName ¶ added in v1.7.1
TypeParamIndexByName returns the index of the type parameter matching on name. If none matching, returns -1.
This is especially useful for generics where interface is something like this:
Doer[T any, K any]{ Start(T) Add(K) error Stop() []K }
But it is used like this:
[ T , K ] type MyDoer = Doer[types.SomeType, otherPkg.SomeOtherThing]
or as an embedded interface:
type MyDoer interface { [ T , K ] Doer[types.SomeType, otherPkg.SomeOtherThing] }
If parsing the Add method for an implementation of this interface, we need to be able to swap out K for whatever the actual type is. K will be at index 1 of the interface's TypeParams, but it will also be at index 1 of the actual type params in either the definition of the interface being mocked or the generic interface it embeds.
type Method ¶
Method is a single method of an interface.
func (*Method) Clone ¶ added in v1.7.1
Clone makes a deep clone of a Method.
This is useful specifically for generics so that generic parameters from source interface methods (e.g. Iface[T any, R any]) can be swapped out with actualized types from a referencing entity (e.g. type OtherIface = Iface[external.Foo, Baz]).
type NamedType ¶
type NamedType struct { Package string // may be empty Type string TypeParams *TypeParametersType }
NamedType is an exported type in a package.
type Package ¶
Package is a Go package. It may be a subset.
type PredeclaredType ¶
type PredeclaredType string
PredeclaredType is a predeclared type such as "int".
type Type ¶
type Type interface { String(pm map[string]string, pkgOverride string) string // contains filtered or unexported methods }
Type is a Go type.
type TypeParametersType ¶ added in v1.7.1
type TypeParametersType struct {
TypeParameters []Type
}
TypeParametersType contains type paramters for a NamedType.