base

package
v0.0.0-...-a7d1dd0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

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

Self-describing criteria that may match (or not match) an input value. Creators of new matchers are *strongly* encouraged not to implement Matcher directly, but to create new matchers using the NewMatcher factory function.

func DeepEqualTo

func DeepEqualTo(expected interface{}) *Matcher

Returns a Matcher that checks if the actual value is (deeply) equal to the given expected value, using `reflect.DeepEqual`.

For an equality test equivalent to `==`, see the `hamcrest/comparison` package.

func DidNotMatch

func DidNotMatch() *Matcher

Returns a Matcher that matches the boolean value false.

func EqualTo

func EqualTo(expected interface{}) *Matcher

Returns a matcher that matches values that are equal to the given expected value, using the equality (==) operator.

func False

func False() *Matcher

Returns a Matcher that matches the boolean value false.

func GreaterThan

func GreaterThan(expected interface{}) *Matcher

Returns a matcher that matches values that are greater-than the given expected value, using the greater-than (<) operator.

func GreaterThanOrEqualTo

func GreaterThanOrEqualTo(expected interface{}) *Matcher

Returns a matcher that matches values that are greater-than-or-equal-to the given expected value, using the greater-than-or-equal-to (>=) operator.

func LessThan

func LessThan(expected interface{}) *Matcher

Returns a matcher that matches values that are less-than the given expected value, using the less-than (<) operator.

func LessThanOrEqualTo

func LessThanOrEqualTo(expected interface{}) *Matcher

Returns a matcher that matches values that are less-than-or-equal-to the given expected value, using the less-than-or-equal-to (<=) operator.

func Matched

func Matched() *Matcher

Returns a Matcher that matches the boolean value true.

func NewMatcher

func NewMatcher(fn interface{}, description SelfDescribing) *Matcher

Creates a new Matcher using the given matching function, with the given description.

Matching functions must have exactly one input parameter. Matching functions must return a *Result or a bool as its first output value. If the first output value is a *Result, that must be its only output value. If the first output value is bool, then that value is used for Result.Matched(), and if present, any second output value is used as the result description. For example, the following signatures are all legal matcher functions:

func(interface{}) *Result
func(interface{}) bool
func(interface{}) (bool, os.Error)
func(string) *Result
func(...*int) bool
func(...io.Reader) (bool os.Error)

func NewMatcherf

func NewMatcherf(fn interface{}, format string, args ...interface{}) *Matcher

Creates a new Matcher using the given matching function, with the given format/args as a description.

func Nil

func Nil() *Matcher

Returns a Matcher that matches if the actual value is nil or the nil value of its type. (Note that this is *not* equivalent to DeeplyEqualTo(nil).)

func NonNil

func NonNil() *Matcher

Returns a Matcher that matches if the actual value is neither nil nor the nil value of its type. (Note that this is *not* equivalent to Not(DeeplyEqualTo(nil)).)

func NotEqualTo

func NotEqualTo(expected interface{}) *Matcher

Returns a matcher that matches values that are not equal to the given expected value, using the inequality (!=) operator.

func True

func True() *Matcher

Returns a Matcher that matches the boolean value true.

func (*Matcher) Comment

func (self *Matcher) Comment(comments ...interface{}) *Matcher

Returns a *new* Matcher similar to this one, but with the given additional comment.

func (*Matcher) Commentf

func (self *Matcher) Commentf(format string, args ...interface{}) *Matcher

Returns a *new* Matcher similar to this one, but with the given additional format/args as a comment.

func (*Matcher) Comments

func (self *Matcher) Comments() []SelfDescribing

Returns a slice of messages that supplement the description.

func (*Matcher) Format

func (self *Matcher) Format(s fmt.State, ch int)

Implementation of SelfDescribing: fmt.Formatter.

func (*Matcher) Match

func (self *Matcher) Match(value interface{}) *Result

Tests the given input value to see if it meets this Matcher's criteria.

func (*Matcher) String

func (self *Matcher) String() string

Implementation of SelfDescribing: fmt.Stringer.

type Result

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

Self-describing result of applying a Matcher to an input value.

func NewResult

func NewResult(matched bool, description SelfDescribing) *Result

Creates a new Result using the given description.

func NewResultf

func NewResultf(matched bool, format string, args ...interface{}) *Result

Creates a new Result using the given format/args as a description.

func (*Result) Causes

func (self *Result) Causes() []*Result

Returns a slice of sub-Results that caused this Result to either match or not match.

func (*Result) Format

func (self *Result) Format(s fmt.State, ch int)

Implements fmt.Formatter.

func (*Result) Matched

func (self *Result) Matched() bool

Returns true if the Match was successful.

func (*Result) Matcher

func (self *Result) Matcher() *Matcher

Returns the Matcher that produced this Result, or nil if this Result was not generated by a Matcher.

func (*Result) String

func (self *Result) String() string

Implements fmt.Stringer.

func (*Result) Value

func (self *Result) Value() interface{}

Returns the value that was given to the Matcher to produce this Result.

Note: If `Matcher()` returns nil, then this will also return nil.

func (*Result) WithCauses

func (self *Result) WithCauses(causes ...*Result) *Result

Returns a new Result, identical to this one, except with the given causes.

func (*Result) WithMatcherAndValue

func (self *Result) WithMatcherAndValue(matcher *Matcher, value interface{}) *Result

Returns a new Result, identical to this one, except with the given matcher and value.

type SelfDescribing

type SelfDescribing interface {
	fmt.Formatter
	fmt.Stringer
}

Hamcrest descriptions implement both fmt.Stringer and fmt.Formatter.

func Description

func Description(format string, args ...interface{}) SelfDescribing

Creates an object that implements fmt.Formatter and fmt.Stringer using args with the same meanings as fmt.Fprintf. Note that this object stores its given parameters and evaluates them lazily.

Jump to

Keyboard shortcuts

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