v0

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

package v0 processes files, subtracting away only the functions declared in the file. These functions can be defined through a function declaration syntax or as an inline definition in a variable declaration.

package templater contains the templating functionality used to convert a general request body template into a body specific to a particular request.

Index

Constants

View Source
const (
	MarkdownFileName = "coverage_report.md"
	MarkdownTemplate = `` /* 928-byte string literal not displayed */

)
View Source
const (
	BlockCovTableFile   = "block_coverage_table.txt"
	FileCovTableFile    = "file_coverage_table.txt"
	PackageCovTableFile = "package_coverage_table.txt"
	ErrorsFile          = "coverage_errors.txt"
)

Variables

This section is empty.

Functions

func AddEvaluator

func AddEvaluator(s ...StatementEvaluator) func(*ruleSet)

func AddMatcher

func AddMatcher(m ...Matcher) func(*ruleSet)

func AddNode

func AddNode(name any, new *node) func(*node)

func AddRuleSet

func AddRuleSet(r ...*ruleSet) func(*ruleSet)

func AddStatement

func AddStatement(statements *statements) func(*node)

func ErrorsToRecord added in v0.2.2

func ErrorsToRecord(errs []Error) [][]string

func Format

func Format(node StatementNode, depth Depth) [][]string

func NewNode

func NewNode(
	options ...func(*node),
) *node

func NewRuleSet

func NewRuleSet(
	options ...func(*ruleSet),
) *ruleSet

func NewStatements

func NewStatements(
	covered int,
	total int,
) *statements

func Open added in v0.2.5

func Open(name string) (io.WriteCloser, error)

func ParseOptions

func ParseOptions(
	global StatementEvaluator,
	options ...Option,
) (*ruleSet, error)

func Ratio

func Ratio(statements Statements) float64

Types

type ArgType

type ArgType int
const (
	Any ArgType = iota
	Fltr
	Name
	Pair
	Index
)

type CommandArgument

type CommandArgument interface {
	Type() ArgType
	Value() any
}

type CommandSurface

type CommandSurface interface {
	Parent() (CommandSurface, bool)
	Command() CommandArgument
}

type Comparable

type Comparable interface {
	Level
	Statements
}

type Context

type Context[T CommandSurface] interface {
	Filter[T]
	CommandSurface
}

type CoverageBelowThresholdError

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

func (*CoverageBelowThresholdError) Error

func (err *CoverageBelowThresholdError) Error() string

type Depth

type Depth int
const (
	PackageDepth Depth = iota + 1
	FileDepth
	BlockDepth
)

type Error added in v0.2.2

type Error struct {
	Err   error
	Place []string
}

func Validate added in v0.2.2

func Validate(node StatementNode, place ...string) []Error

func ValidatePreviousStatements added in v0.2.2

func ValidatePreviousStatements(statements Statements, place []string) []Error

type ErrorFileOutputter added in v0.2.5

type ErrorFileOutputter struct {
	Writer         RecordWriter
	Open           func(name string) (io.WriteCloser, error)
	Validate       func(node StatementNode, place ...string) []Error
	ErrorsToRecord func(errs []Error) [][]string
}

func NewErrorOutputter added in v0.2.5

func NewErrorOutputter(options ...func(*ErrorFileOutputter)) *ErrorFileOutputter

func (*ErrorFileOutputter) WriteOut added in v0.2.5

func (output *ErrorFileOutputter) WriteOut(name string, node StatementNode) error

type ErrorOutputter added in v0.2.5

type ErrorOutputter interface {
	WriteOut(name string, node StatementNode) error
}

type Evaluator

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

func CreateEvaluator

func CreateEvaluator(
	root string,
	profile string,
	name string,
) (*Evaluator, error)

func NewEvaluator

func NewEvaluator(node Node) *Evaluator

func (*Evaluator) Evaluate

func (evaluator *Evaluator) Evaluate(
	global float64,
	options ...Option,
) (StatementNode, error)

type ExactMatcher

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

func NewExactMatcher

func NewExactMatcher(match string) *ExactMatcher

func (*ExactMatcher) Match

func (matcher *ExactMatcher) Match(matches any) bool

type ExactPairMatcher

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

func NewExactPairMatcher

func NewExactPairMatcher(pair NamePair) *ExactPairMatcher

func (*ExactPairMatcher) Match

func (matcher *ExactPairMatcher) Match(matches any) bool

type ExcludeCommand

type ExcludeCommand struct{}

func NewExcludeCommand

func NewExcludeCommand() *ExcludeCommand

func (*ExcludeCommand) Apply

func (command *ExcludeCommand) Apply(old Statements) Statements

type Executor added in v0.2.5

type Executor struct {
	*template.Template
}

func NewExecutor added in v0.2.5

func NewExecutor(content string) (*Executor, error)

type FallbackCommand added in v0.2.5

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

func NewFallbackCommand added in v0.2.5

func NewFallbackCommand(fallback StatementEvaluator) *FallbackCommand

func (*FallbackCommand) Apply added in v0.2.5

func (command *FallbackCommand) Apply(statements Statements) Statements

type FileContext

type FileContext interface {
	FunctionParent
	CommandSurface
}

type FileFactory added in v0.2.5

type FileFactory interface {
	NewFile() (io.WriteCloser, error)
}

type FileInstance

type FileInstance interface {
	CommandSurface
	FunctionParent
	Method(receiver string, name string) CommandSurface
	Function(name string) CommandSurface
	Literal(index int) CommandSurface
}

type FileParent

type FileParent interface {
	Files() Files
}

type FileProcessor

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

func NewFileProcessor

func NewFileProcessor(
	fst *token.FileSet,
	tree *ast.File,
	directory string,
	fileName string,
) *FileProcessor

func (*FileProcessor) Process

func (processor *FileProcessor) Process() []*declarations.Decl

type Files

type Files Context[FileContext]

func AllFiles

func AllFiles() Files

type Filter

type Filter[T CommandSurface] interface {
	Filter(string) T
}

type Flusher

type Flusher interface {
	Flush() error
	io.Writer
}

type FlusherBuilder

type FlusherBuilder interface {
	NewWriter(output io.Writer) Flusher
}

type FunctionParent

type FunctionParent interface {
	Functions() Functions
}

type Functions

type Functions Context[CommandSurface]

func AllFunctions

func AllFunctions() Functions

type GenericWriter added in v0.2.5

type GenericWriter[T any] interface {
	Write(t T) error
}

type Global added in v0.2.6

type Global struct {
	Covered    string
	Statements string
	Ratio      string
}

type GlobalOption added in v0.2.3

type GlobalOption func() ([]*ruleSet, error)

type IndexMatcher

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

func NewIndexMatcher

func NewIndexMatcher(index int) *IndexMatcher

func (*IndexMatcher) Match

func (matcher *IndexMatcher) Match(matches any) bool

type InvalidCommandArgumentTypeError

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

func (*InvalidCommandArgumentTypeError) Error

type InvalidCommandArgumentValueTypeError

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

func (*InvalidCommandArgumentValueTypeError) Error

type InvalidMinimumArgumentError

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

func (*InvalidMinimumArgumentError) Error

func (err *InvalidMinimumArgumentError) Error() string

type Level

type Level int
const (
	Proj Level = iota
	Pack
	File
	Bloc
)

type MarkDownTemplate added in v0.2.5

type MarkDownTemplate struct {
	Global  []string
	Errors  [][]string
	Package [][]string
	File    [][]string
	Block   [][]string
	Valid   bool
}

type MarkdownOutputter added in v0.2.5

type MarkdownOutputter struct {
	WriterFactory  WriterFactory
	Format         func(node StatementNode, depth Depth) [][]string
	Validate       func(node StatementNode, place ...string) []Error
	ErrorsToRecord func(errs []Error) [][]string
}

func NewMarkdownOutputter added in v0.2.5

func NewMarkdownOutputter(options ...func(*MarkdownOutputter)) *MarkdownOutputter

func (*MarkdownOutputter) WriteOut added in v0.2.5

func (outputter *MarkdownOutputter) WriteOut(node StatementNode) error

type Matcher

type Matcher interface {
	Match(matches any) bool
}

type MinimumCommand

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

func NewMinimumCommand

func NewMinimumCommand(minimum float64) (*MinimumCommand, error)

func (*MinimumCommand) Apply

func (command *MinimumCommand) Apply(statements Statements) Statements

type MockExecutor added in v0.2.5

type MockExecutor struct {
	OnExecute func(wr io.Writer, data any) error
}

func (*MockExecutor) Execute added in v0.2.5

func (executor *MockExecutor) Execute(wr io.Writer, data any) error

type MockRenderer added in v0.2.5

type MockRenderer[T any] struct {
	OnRender func(vars T) (io.Reader, error)
}

func (*MockRenderer[T]) Render added in v0.2.5

func (renderer *MockRenderer[T]) Render(vars T) (io.Reader, error)

type MultiFileOutputter added in v0.2.5

type MultiFileOutputter struct {
	ErrorsFile          string
	BlockCovTableFile   string
	FileCovTableFile    string
	PackageCovTableFile string

	RecordsOut RecordOutputter
	ErrorsOut  ErrorOutputter
}

func NewMultiFileOutputter added in v0.2.5

func NewMultiFileOutputter(options ...func(*MultiFileOutputter)) *MultiFileOutputter

func (*MultiFileOutputter) WriteOut added in v0.2.5

func (outputter *MultiFileOutputter) WriteOut(node StatementNode) error

type NamePair

type NamePair struct {
	X string
	Y string
}

type Node

type Node interface {
	Children() map[any]Node
	Leaf() (Statements, bool)
}

type NoopCommand

type NoopCommand struct{}

func NewNoopCommand

func NewNoopCommand() *NoopCommand

func (*NoopCommand) Apply

func (command *NoopCommand) Apply(statements Statements) Statements

type NoopMatcher

type NoopMatcher struct{}

func NewNoopMatcher

func NewNoopMatcher() *NoopMatcher

func (*NoopMatcher) Match

func (matcher *NoopMatcher) Match(matches any) bool

type NoopReader added in v0.2.5

type NoopReader struct{}

func (*NoopReader) Close added in v0.2.5

func (*NoopReader) Close() error

func (*NoopReader) Read added in v0.2.5

func (*NoopReader) Read([]byte) (int, error)

func (*NoopReader) WriteTo added in v0.2.5

func (*NoopReader) WriteTo(io.Writer) (int64, error)

type NoopRenderer added in v0.2.5

type NoopRenderer[T any] struct {
}

func (*NoopRenderer[T]) Render added in v0.2.5

func (renderer *NoopRenderer[T]) Render(vars T) (io.Reader, error)

type OSFileFactory added in v0.2.5

type OSFileFactory struct {
	FileName string
	Open     func(fileName string) (*os.File, error)
}

func NewOSFileFactory added in v0.2.5

func NewOSFileFactory(options ...func(*OSFileFactory)) *OSFileFactory

func (*OSFileFactory) NewFile added in v0.2.5

func (factory *OSFileFactory) NewFile() (io.WriteCloser, error)

type Option

type Option func() ([]*ruleSet, error)

func Exclude

func Exclude(surfaces ...CommandSurface) Option

func Fallback added in v0.2.5

func Fallback(min float64, surfaces ...CommandSurface) Option

func Min

func Min(min float64, surfaces ...CommandSurface) Option

type Outputter added in v0.2.5

type Outputter interface {
	WriteOut(node StatementNode) error
}

type PackageContext

type PackageContext interface {
	FileParent
	FunctionParent
	CommandSurface
}

type PackageInstance

type PackageInstance interface {
	CommandSurface
	FileParent
	FunctionParent
	File(name string) FileInstance
}

func Package

func Package(name string) PackageInstance

type Packages

type Packages Context[PackageContext]

func AllPackages

func AllPackages() Packages

type ProfileReader

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

func NewProfileReader

func NewProfileReader(
	root string,
	profile string,
	name string,
) *ProfileReader

func (*ProfileReader) CreateNodeTree

func (reader *ProfileReader) CreateNodeTree() (Node, error)

type RecordFileOutputter added in v0.2.5

type RecordFileOutputter struct {
	Writer RecordWriter
	Open   func(name string) (io.WriteCloser, error)
	Format func(node StatementNode, depth Depth) [][]string
}

func NewRecordOutputter added in v0.2.5

func NewRecordOutputter(options ...func(*RecordFileOutputter)) *RecordFileOutputter

func (*RecordFileOutputter) WriteOut added in v0.2.5

func (output *RecordFileOutputter) WriteOut(name string, node StatementNode, depth Depth) error

type RecordOutputter added in v0.2.5

type RecordOutputter interface {
	WriteOut(name string, node StatementNode, depth Depth) error
}

type RecordWriter added in v0.2.5

type RecordWriter interface {
	Write(w io.Writer, records [][]string) error
}

type RegexpMatcher

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

func NewRegexpMatcher

func NewRegexpMatcher(matchString func(s string) bool) *RegexpMatcher

func (*RegexpMatcher) Match

func (matcher *RegexpMatcher) Match(matches any) bool

type RuleSet

type RuleSet interface {
	Children(name any) RuleSet
	StatementEvaluator
}

type StatementEvaluator

type StatementEvaluator interface {
	Apply(Statements) Statements
}

type StatementNode

type StatementNode interface {
	Statements
	Children() map[any]StatementNode
}

type Statements

type Statements interface {
	Covered() int
	Total() int
	Valid() error
	Previous() Statements
}

type TabWriterBuilder

type TabWriterBuilder struct {
	Writer   func(output io.Writer, minwidth int, tabwidth int, padding int, padchar byte, flags uint) *tabwriter.Writer
	MinWidth int
	TabWidth int
	Padding  int
	Padchar  byte
	Flags    uint
}

func NewTabWriterBuilder

func NewTabWriterBuilder(options ...func(*TabWriterBuilder)) *TabWriterBuilder

func (*TabWriterBuilder) NewWriter

func (builder *TabWriterBuilder) NewWriter(output io.Writer) Flusher

type TemplateExecuter added in v0.2.5

type TemplateExecuter interface {
	Execute(wr io.Writer, data any) error
}

type TemplateExecutorFactory added in v0.2.5

type TemplateExecutorFactory struct {
	Template       string
	CreateExecutor func(content string) (*Executor, error)
}

func NewTemplateExecutorFactory added in v0.2.5

func NewTemplateExecutorFactory(options ...func(*TemplateExecutorFactory)) *TemplateExecutorFactory

func (*TemplateExecutorFactory) NewExecutor added in v0.2.5

func (factory *TemplateExecutorFactory) NewExecutor() (TemplateExecuter, error)

type TemplateFactory added in v0.2.5

type TemplateFactory interface {
	NewExecutor() (TemplateExecuter, error)
}

type TemplateRenderer added in v0.2.5

type TemplateRenderer[T any] interface {
	Render(vars T) (io.Reader, error)
}

TemplateRenderer is an interface with a Render method. Render converts a generic to an io.Reader, or an error.

type TemplateWriter added in v0.2.5

type TemplateWriter[T any] struct {
	Exec TemplateExecuter
	File io.WriteCloser
}

func NewTemplateWriter added in v0.2.5

func NewTemplateWriter[T any](
	Exec TemplateExecuter,
	File io.WriteCloser,
) *TemplateWriter[T]

func (*TemplateWriter[T]) Write added in v0.2.5

func (writer *TemplateWriter[T]) Write(t T) error

type TemplateWriterFactory added in v0.2.5

type TemplateWriterFactory[T any] struct {
	TemplateFactory TemplateFactory
	FileFactory     FileFactory
	CreateWriter    func(Exec TemplateExecuter, File io.WriteCloser) *TemplateWriter[T]
}

func NewWriterFactory added in v0.2.5

func NewWriterFactory[T any](options ...func(*TemplateWriterFactory[T])) *TemplateWriterFactory[T]

func (*TemplateWriterFactory[T]) NewWriter added in v0.2.5

func (factory *TemplateWriterFactory[T]) NewWriter() (GenericWriter[T], error)

type Templater added in v0.2.5

type Templater[T any] struct {
	// contains filtered or unexported fields
}

Templater is a wrapper struct around the functionality of the golang wrapper.

func NewTemplater added in v0.2.5

func NewTemplater[T any](templ TemplateExecuter) *Templater[T]

NewTemplater creates a new Templater. It must be given a template in the form of a string as a parameter.

func (*Templater[T]) Render added in v0.2.5

func (templater *Templater[T]) Render(vars T) (io.Reader, error)

Render converts a template into an io.Reader (which can be further reduced to string) given variables specific to that template.

type Writer

type Writer struct {
	Builder FlusherBuilder
	Delim   string
}

func NewWriter

func NewWriter(options ...func(*Writer)) *Writer

func (*Writer) Write

func (writer *Writer) Write(w io.Writer, records [][]string) error

type WriterFactory added in v0.2.5

type WriterFactory interface {
	NewWriter() (GenericWriter[MarkDownTemplate], error)
}

Jump to

Keyboard shortcuts

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