Documentation ¶
Index ¶
- type Matcher
- func DeepEqualTo(expected interface{}) *Matcher
- func DidNotMatch() *Matcher
- func EqualTo(expected interface{}) *Matcher
- func False() *Matcher
- func GreaterThan(expected interface{}) *Matcher
- func GreaterThanOrEqualTo(expected interface{}) *Matcher
- func LessThan(expected interface{}) *Matcher
- func LessThanOrEqualTo(expected interface{}) *Matcher
- func Matched() *Matcher
- func NewMatcher(fn interface{}, description SelfDescribing) *Matcher
- func NewMatcherf(fn interface{}, format string, args ...interface{}) *Matcher
- func Nil() *Matcher
- func NonNil() *Matcher
- func NotEqualTo(expected interface{}) *Matcher
- func True() *Matcher
- func (self *Matcher) Comment(comments ...interface{}) *Matcher
- func (self *Matcher) Commentf(format string, args ...interface{}) *Matcher
- func (self *Matcher) Comments() []SelfDescribing
- func (self *Matcher) Format(s fmt.State, ch int)
- func (self *Matcher) Match(value interface{}) *Result
- func (self *Matcher) String() string
- type Result
- func (self *Result) Causes() []*Result
- func (self *Result) Format(s fmt.State, ch int)
- func (self *Result) Matched() bool
- func (self *Result) Matcher() *Matcher
- func (self *Result) String() string
- func (self *Result) Value() interface{}
- func (self *Result) WithCauses(causes ...*Result) *Result
- func (self *Result) WithMatcherAndValue(matcher *Matcher, value interface{}) *Result
- type SelfDescribing
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 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 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 ¶
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 (*Matcher) Comment ¶
Returns a *new* Matcher similar to this one, but with the given additional comment.
func (*Matcher) Commentf ¶
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.
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 ¶
Creates a new Result using the given format/args as a description.
func (*Result) Causes ¶
Returns a slice of sub-Results that caused this Result to either match or not match.
func (*Result) Matcher ¶
Returns the Matcher that produced this Result, or nil if this Result was not generated by a Matcher.
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 ¶
Returns a new Result, identical to this one, except with the given causes.
func (*Result) WithMatcherAndValue ¶
Returns a new Result, identical to this one, except with the given matcher and value.
type SelfDescribing ¶
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.