predicate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatContextValues

func FormatContextValues(values []ContextValue) string

FormatContextValues returns a string containing the formated print-out of the context values.

Types

type ContextValue

type ContextValue struct {
	Name  string
	Value interface{}
	Pre   bool
}

ContextValue capture one original, intermediate or final value generated during the evaluation of a predicate. Each value has a `Name`, a `Value`, and a `Pre` flag indicating if the value is a preformatted string that should be printed as is, or an actual value that should be printed with adequate formatting.

type Predicate

type Predicate struct {
	Transformations []Transformation
	Description     string
	Func            PredicateFunc
}

Predicate captures a complete predicate chain with `Transformations`, a `Description` and an actual evaluation function `Func`.

func (*Predicate) Evaluate

func (p *Predicate) Evaluate(value interface{}) (success bool, context []ContextValue)

Evaluate evaluates the full predicate chain on the given `value`, and returns a `success` flag and, upon failure, a `context` containing all the relevant values captured during evaluation.

func (*Predicate) FormatDescription

func (p *Predicate) FormatDescription(value string) string

FormatDescription return a formatted description of the full predicate chain, using the `value` string to represent the input value.

func (*Predicate) RegisterPredicate

func (p *Predicate) RegisterPredicate(desc string, f PredicateFunc)

RegisterPredicate sets the predicate evaluation function and description for the current predicate.

func (*Predicate) RegisterTransformation

func (p *Predicate) RegisterTransformation(desc string, f TransformFunc)

RegisterTransformation appends the given transformation to the list of transformations attached to the predicate.

type PredicateFunc

type PredicateFunc func(
	value interface{}) (
	success bool, ctx []ContextValue, err error)

PredicateFunc is the function type for use in a `Predicate`.

type T

type T interface {
	Helper()
	Errorf(format string, args ...interface{})
	FailNow()
	Cleanup(f func())
}

T is a minimal abstracted interface of testing.T for the purpose of // predicate construction and evaluation.

type TransformFunc

type TransformFunc func(
	value interface{}) (
	result interface{}, ctx []ContextValue, err error)

TransformFunc is the function type for use in a `Transformation`.

type Transformation

type Transformation struct {
	Description string
	Func        TransformFunc
}

Transformation captures one transformation step in the predicate evaluation chain, with a `Description` and an actual transformation function `Func`.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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