parser

package
v0.0.0-...-2d975fa Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parser contains the parser for reading Go files and building the interface definitions needed to generate mocks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IncludingInterfaceFilter

type IncludingInterfaceFilter struct {
	InterfacesToInclude []string
}

IncludingInterfaceFilter is an InterfaceFilter that works based on an allow-list of interface names.

func (*IncludingInterfaceFilter) Include

func (f *IncludingInterfaceFilter) Include(name string) bool

Include returns true if the specified interface should be mocked, false otherwise.

type InterfaceFilter

type InterfaceFilter interface {
	// Include indicates that the specified interface should be included in the set of interfaces
	// to generate.
	Include(name string) bool
}

InterfaceFilter is used to decide which interfaces mocks should be generated for.

type MethodDefinition

type MethodDefinition struct {
	// Name is the name of the method.
	Name string

	// Parameters contains the parameters passed to the method.
	Parameters []ParameterDefinition

	// Results contains the method results.
	Results []ResultDefinition

	// Comment contains any comments added to the method.
	Comment string
}

MethodDefinition defines a method in an interface.

type MockedInterface

type MockedInterface struct {
	// Name contains the name of the interface.
	Name string

	// PackageName contains the name of the package that the interface belongs to.
	PackageName string

	// Methods contains the list of methods in the interface.
	Methods []MethodDefinition
}

MockedInterface represents an interface that a mock should be generated for.

func Parse

func Parse(reader io.Reader, filter InterfaceFilter) ([]MockedInterface, error)

Parse parses the source contained in the reader.

type ParameterDefinition

type ParameterDefinition struct {
	// Name is the name of the parameter.
	Name string

	// Type is the parameter's type.
	Type string
}

ParameterDefinition contains information about a method parameter.

type ResultDefinition

type ResultDefinition struct {
	// Name is the name of the method result. This can be empty if the result is not named.
	Name string

	// Type is the type of the result.
	Type string
}

ResultDefinition contains information about a method result.

Directories

Path Synopsis
mocks
interfacefilter
Code generated by Kelpie.
Code generated by Kelpie.

Jump to

Keyboard shortcuts

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