strategy

package
v0.0.0-...-60cbbbe Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvailableStrategies = map[string]Strategy{
	"strict": StrictEqualStrategy,
	"type":   TypeEqualStrategy,
}

Mapped list of available strategies

Functions

This section is empty.

Types

type Archetype

type Archetype struct {
	Value    interface{} `json:"value"`
	Strategy string      `json:"strategy"`
}

Archetype allows the developer to define certain content to trigger a different assertion strategy instead of the default 'strict' strategy

func LoadArchetypes

func LoadArchetypes(r io.Reader) ([]*Archetype, error)

load archetypes from json encoded reader content

func (*Archetype) Fits

func (a *Archetype) Fits(val interface{}) bool

returns whether a given example value fit the defined archetype @todo this is quite fragicle since a.Value and val can be of similar but unequal types: float64(42) int64(42) will not match

func (*Archetype) ToStrategy

func (a *Archetype) ToStrategy() (Strategy, error)

returns the assert strategy for the archetype

type AssertFunc

type AssertFunc func(expected, actual interface{}) error

func Parse

func Parse(example interface{}, ats []*Archetype) (AssertFunc, error)

parse an example value to determine how the actual value will be asserted, (e.g. strict equal, type only)

func StrictEqualStrategy

func StrictEqualStrategy() AssertFunc

Actual value should be exactly equal to the example

func TypeEqualStrategy

func TypeEqualStrategy() AssertFunc

Actual value only needs to be of the same type as the example

type Strategy

type Strategy func() AssertFunc

Jump to

Keyboard shortcuts

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