Documentation ¶
Overview ¶
Package assert provides basic assertions for unit tests.
Example Usage ¶
The following examples show how to use this library:
import ( "testing" . "v2ray.com/ext/assert" ) func TestSomething(t *testing.T) { assert := With(t) a := 10 b := 1 assert(a, Equals, b) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AtLeast = CreateMatcher(func(v interface{}, exp interface{}) bool {
return !callInternal(less, v, exp)
}, "less than")
View Source
var AtMost = CreateMatcher(func(v interface{}, exp interface{}) bool {
return !callInternal(greater, v, exp)
}, "less than or equals to")
View Source
var Equals = CreateMatcher(func(v interface{}, exp interface{}) bool { vt := reflect.TypeOf(v) op, found := equals[vt] if found { return op.call(v, []interface{}{exp}) } return v == exp }, "equals to")
Equals is a Matcher that expects two given values are equal to each other.
View Source
var GreaterThan = CreateMatcher(func(v interface{}, exp interface{}) bool {
return callInternal(greater, v, exp)
}, "less than")
View Source
var HasDone = CreateMatcher(func(ctx context.Context) bool { select { case <-ctx.Done(): return true default: return false } }, "has done.")
View Source
var HasPrefix = CreateMatcher(func(a, b string) bool { return strings.HasPrefix(a, b) }, "has prefix")
View Source
var HasStringElement = CreateMatcher(func(a []string, b string) bool { for _, v := range a { if v == b { return true } } return false }, "contains string element")
View Source
var HasSubstring = CreateMatcher(func(a, b string) bool { return strings.Contains(a, b) }, "contains substring")
View Source
var HasSuffix = CreateMatcher(func(a, b string) bool { return strings.HasSuffix(a, b) }, "has suffix")
View Source
var Implements = CreateMatcher(func(v interface{}, exp interface{}) bool { return reflect.TypeOf(v).Implements(reflect.TypeOf(exp).Elem()) }, "implements")
View Source
var IsEmpty = CreateMatcher(func(v interface{}) bool { return reflect.ValueOf(v).Len() == 0 }, "is empty")
View Source
var IsFalse = CreateMatcher(func(v bool) bool {
return !v
}, "is false")
View Source
var IsNegative = CreateMatcher(func(v interface{}, exp interface{}) bool {
return callInternal(less, v, 0)
}, "is negative")
View Source
var IsNil = CreateMatcher(func(v interface{}) bool { return v == nil || reflect.ValueOf(v).IsNil() }, "is nil")
View Source
var IsNotNil = CreateMatcher(func(v interface{}) bool { return v != nil }, "is not nil")
View Source
var IsPositive = CreateMatcher(func(v interface{}, exp interface{}) bool {
return callInternal(greater, v, 0)
}, "is positive")
View Source
var IsTrue = CreateMatcher(func(v bool) bool {
return v
}, "is true")
View Source
var LessThan = CreateMatcher(func(v interface{}, exp interface{}) bool {
return callInternal(less, v, exp)
}, "less than")
LessThan expects the given value is less than the expectation.
View Source
var NotEquals = CreateMatcher(func(v interface{}, exp interface{}) bool { vt := reflect.TypeOf(v) op, found := equals[vt] if found { return !op.call(v, []interface{}{exp}) } return v != exp }, "not equals to")
NotEquals is a Matcher that expects two given values are not equal to each other.
View Source
var Panics = CreateMatcher(func(v interface{}) (ret bool) { defer func() { if x := recover(); x != nil { ret = true } }() if vf, ok := v.(func()); ok { vf() } return false }, "panics")
Functions ¶
func RegisterEqualsMatcher ¶
func RegisterEqualsMatcher(f interface{})
func RegisterGreaterThanMatcher ¶
func RegisterGreaterThanMatcher(f interface{})
func RegisterLessThanMatcher ¶
func RegisterLessThanMatcher(f interface{})
Types ¶
Click to show internal directories.
Click to hide internal directories.