Documentation
¶
Overview ¶
Package assert implements assertion functions for verifying invariants to extend the built-in testing package.
Index ¶
- Variables
- func ContainsElement(t *testing.T, source, expect any, message ...any) error
- func ContainsElementNow(t *testing.T, source, expect any, message ...any) error
- func ContainsString(t *testing.T, str, substr string, message ...any) error
- func ContainsStringNow(t *testing.T, str, substr string, message ...any) error
- func DeepEqual(t *testing.T, actual, expect any, message ...any) error
- func DeepEqualNow(t *testing.T, actual, expect any, message ...any) error
- func Equal(t *testing.T, actual, expect any, message ...any) error
- func EqualNow(t *testing.T, actual, expect any, message ...any) error
- func Gt(t *testing.T, v1, v2 any, message ...string) error
- func GtNow(t *testing.T, v1, v2 any, message ...string) error
- func Gte(t *testing.T, v1, v2 any, message ...string) error
- func GteNow(t *testing.T, v1, v2 any, message ...string) error
- func HasPrefixString(t *testing.T, str, prefix string, message ...any) error
- func HasPrefixStringNow(t *testing.T, str, prefix string, message ...any) error
- func HasSuffixString(t *testing.T, str, suffix string, message ...any) error
- func HasSuffixStringNow(t *testing.T, str, suffix string, message ...any) error
- func Lt(t *testing.T, v1, v2 any, message ...string) error
- func LtNow(t *testing.T, v1, v2 any, message ...string) error
- func Lte(t *testing.T, v1, v2 any, message ...string) error
- func LteNow(t *testing.T, v1, v2 any, message ...string) error
- func MapHasKey(t *testing.T, m, key any, message ...any) error
- func MapHasKeyNow(t *testing.T, m, key any, message ...any) error
- func MapHasValue(t *testing.T, m, value any, message ...any) error
- func MapHasValueNow(t *testing.T, m, value any, message ...any) error
- func Match(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error
- func MatchNow(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error
- func MatchString(t *testing.T, val, pattern string, message ...any) error
- func MatchStringNow(t *testing.T, val, pattern string, message ...any) error
- func Nil(t *testing.T, val any, message ...any) error
- func NilNow(t *testing.T, val any, message ...any) error
- func NotContainsElement(t *testing.T, source, expect any, message ...any) error
- func NotContainsElementNow(t *testing.T, source, expect any, message ...any) error
- func NotContainsString(t *testing.T, str, substr string, message ...any) error
- func NotContainsStringNow(t *testing.T, str, substr string, message ...any) error
- func NotDeepEqual(t *testing.T, actual, expect any, message ...any) error
- func NotDeepEqualNow(t *testing.T, actual, expect any, message ...any) error
- func NotEqual(t *testing.T, actual, expect any, message ...any) error
- func NotEqualNow(t *testing.T, actual, expect any, message ...any) error
- func NotHasPrefixString(t *testing.T, str, prefix string, message ...any) error
- func NotHasPrefixStringNow(t *testing.T, str, prefix string, message ...any) error
- func NotHasSuffixString(t *testing.T, str, suffix string, message ...any) error
- func NotHasSuffixStringNow(t *testing.T, str, suffix string, message ...any) error
- func NotMapHasKey(t *testing.T, m, key any, message ...any) error
- func NotMapHasKeyNow(t *testing.T, m, key any, message ...any) error
- func NotMapHasValue(t *testing.T, m, value any, message ...any) error
- func NotMapHasValueNow(t *testing.T, m, value any, message ...any) error
- func NotMatch(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error
- func NotMatchNow(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error
- func NotMatchString(t *testing.T, val, pattern string, message ...any) error
- func NotMatchStringNow(t *testing.T, val, pattern string, message ...any) error
- func NotNil(t *testing.T, val any, message ...any) error
- func NotNilNow(t *testing.T, val any, message ...any) error
- func NotPanic(t *testing.T, fn func(), message ...any) error
- func NotPanicNow(t *testing.T, fn func(), message ...any) error
- func NotTrue(t *testing.T, val any, message ...any) error
- func NotTrueNow(t *testing.T, val any, message ...any) error
- func Panic(t *testing.T, fn func(), message ...any) error
- func PanicNow(t *testing.T, fn func(), message ...any) error
- func True(t *testing.T, val any, message ...any) error
- func TrueNow(t *testing.T, val any, message ...any) error
- type Assertion
- func (a *Assertion) ContainsElement(source, expect any, message ...any) error
- func (a *Assertion) ContainsElementNow(source, expect any, message ...any) error
- func (a *Assertion) ContainsString(str, substr string, message ...any) error
- func (a *Assertion) ContainsStringNow(str, substr string, message ...any) error
- func (a *Assertion) DeepEqual(actual, expect any, message ...any) error
- func (a *Assertion) DeepEqualNow(actual, expect any, message ...any) error
- func (a *Assertion) Equal(actual, expect any, message ...any) error
- func (a *Assertion) EqualNow(actual, expect any, message ...any) error
- func (a *Assertion) Gt(v1, v2 any, message ...string) error
- func (a *Assertion) GtNow(v1, v2 any, message ...string) error
- func (a *Assertion) Gte(v1, v2 any, message ...string) error
- func (a *Assertion) GteNow(v1, v2 any, message ...string) error
- func (a *Assertion) HasPrefixString(str, prefix string, message ...any) error
- func (a *Assertion) HasPrefixStringNow(str, prefix string, message ...any) error
- func (a *Assertion) HasSuffixString(str, suffix string, message ...any) error
- func (a *Assertion) HasSuffixStringNow(str, suffix string, message ...any) error
- func (a *Assertion) Lt(v1, v2 any, message ...string) error
- func (a *Assertion) LtNow(v1, v2 any, message ...string) error
- func (a *Assertion) Lte(v1, v2 any, message ...string) error
- func (a *Assertion) LteNow(v1, v2 any, message ...string) error
- func (a *Assertion) MapHasKey(m, key any, message ...any) error
- func (a *Assertion) MapHasKeyNow(m, key any, message ...any) error
- func (a *Assertion) MapHasValue(m, value any, message ...any) error
- func (a *Assertion) MapHasValueNow(m, value any, message ...any) error
- func (a *Assertion) Match(val string, pattern *regexp.Regexp, message ...any) error
- func (a *Assertion) MatchNow(val string, pattern *regexp.Regexp, message ...any) error
- func (a *Assertion) MatchString(val, pattern string, message ...any) error
- func (a *Assertion) MatchStringNow(val, pattern string, message ...any) error
- func (a *Assertion) Nil(val any, message ...any) error
- func (a *Assertion) NilNow(val any, message ...any) error
- func (a *Assertion) NotContainsElement(source, expect any, message ...any) error
- func (a *Assertion) NotContainsElementNow(source, expect any, message ...any) error
- func (a *Assertion) NotContainsString(str, substr string, message ...any) error
- func (a *Assertion) NotContainsStringNow(str, substr string, message ...any) error
- func (a *Assertion) NotDeepEqual(actual, expect any, message ...any) error
- func (a *Assertion) NotDeepEqualNow(actual, expect any, message ...any) error
- func (a *Assertion) NotEqual(actual, expect any, message ...any) error
- func (a *Assertion) NotEqualNow(actual, expect any, message ...any) error
- func (a *Assertion) NotHasPrefixString(str, prefix string, message ...any) error
- func (a *Assertion) NotHasPrefixStringNow(str, prefix string, message ...any) error
- func (a *Assertion) NotHasSuffixString(str, suffix string, message ...any) error
- func (a *Assertion) NotHasSuffixStringNow(str, suffix string, message ...any) error
- func (a *Assertion) NotMapHasKey(m, key any, message ...any) error
- func (a *Assertion) NotMapHasKeyNow(m, key any, message ...any) error
- func (a *Assertion) NotMapHasValue(m, value any, message ...any) error
- func (a *Assertion) NotMapHasValueNow(m, value any, message ...any) error
- func (a *Assertion) NotMatch(val string, pattern *regexp.Regexp, message ...any) error
- func (a *Assertion) NotMatchNow(val string, pattern *regexp.Regexp, message ...any) error
- func (a *Assertion) NotMatchString(val, pattern string, message ...any) error
- func (a *Assertion) NotMatchStringNow(val, pattern string, message ...any) error
- func (a *Assertion) NotNil(val any, message ...any) error
- func (a *Assertion) NotNilNow(val any, message ...any) error
- func (a *Assertion) NotPanic(fn func(), message ...any) error
- func (a *Assertion) NotPanicNow(fn func(), message ...any) error
- func (a *Assertion) NotTrue(val any, message ...any) error
- func (a *Assertion) NotTrueNow(val any, message ...any) error
- func (a *Assertion) Panic(fn func(), message ...any) error
- func (a *Assertion) PanicNow(fn func(), message ...any) error
- func (assertion *Assertion) Run(name string, f func(a *Assertion)) bool
- func (a *Assertion) True(val any, message ...any) error
- func (a *Assertion) TrueNow(val any, message ...any) error
- type AssertionError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotArray indicates that the value must be a slice or an array. ErrNotArray error = errors.New("the value must be a slice or an array") // ErrNotMap indicates that the value must be a map. ErrNotMap error = errors.New("the value must be a map") // ErrNotOrderable indicates that the value must be orderable. ErrNotOrderable error = errors.New("the value must be orderable") // ErrNotSameType indicates that both values must be the same type. ErrNotSameType error = errors.New("the values must be the same type") // ErrRequireT indicates that the instance of testing.T is a required parameter. ErrRequireT error = errors.New("testing.T is required") )
Functions ¶
func ContainsElement ¶ added in v0.2.0
NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.
assertion.ContainsElement([]int{1, 2, 3}, 1) // success assertion.ContainsElement([]int{1, 2, 3}, 3) // success assertion.ContainsElement([]int{1, 2, 3}, 4) // fail
func ContainsElementNow ¶ added in v0.2.0
ContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.
assertion.ContainsElementNow([]int{1, 2, 3}, 1) // success assertion.ContainsElementNow([]int{1, 2, 3}, 3) // success assertion.ContainsElementNow([]int{1, 2, 3}, 4) // fail and stop the execution // never runs
func ContainsString ¶ added in v0.1.7
ContainsString tests whether the string contains the substring or not, and it set the result to fail if the string does not contains the substring.
ContainsString(t, "Hello world", "") // success ContainsString(t, "Hello world", "Hello") // success ContainsString(t, "Hello world", "world") // success ContainsString(t, "Hello world", "hello") // fail
func ContainsStringNow ¶ added in v0.1.7
ContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string does not contains the substring.
ContainsStringNow(t, "Hello world", "") // success ContainsStringNow(t, "Hello world", "Hello") // success ContainsStringNow(t, "Hello world", "world") // success ContainsStringNow(t, "Hello world", "hello") // fail and stop the execution // never runs
func DeepEqual ¶
DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to fail if they are not deeply equal, and it doesn't stop the execution.
DeepEqual(t, 1, 1) // success DeepEqual(t, "ABC", "ABC") // success DeepEqual(t, 1, 0) // fail DeepEqual(t, 1, int64(1)) // fail
func DeepEqualNow ¶ added in v0.1.2
DeepEqualNow tests the deep equality between actual and expect parameters, and it'll stop the execution if they are not deeply equal.
DeepEqualNow(t, 1, 1) // success DeepEqualNow(t, "ABC", "ABC") // success DeepEqualNow(t, 1, int64(1)) // fail and terminate // never run
func Equal ¶ added in v0.1.5
Equal tests the equality between actual and expect parameters. It'll set the result to fail if they are not equal, and it doesn't stop the execution.
Equal(t, 1, 1) // success Equal(t, "ABC", "ABC") // success Equal(t, 1, int64(1)) // success Equal(t, 1, uint64(1)) // fail Equal(t, 1, 0) // fail
func EqualNow ¶ added in v0.1.5
EqualNow tests the equality between actual and expect parameters, and it'll stop the execution if they are not equal.
EqualNow(t, 1, 1) // success EqualNow(t, "ABC", "ABC") // success EqualNow(t, 1, int64(1)) // success EqualNow(t, 1, 0) // fail and terminate never run
func Gt ¶ added in v1.0.0
Gt compares the values and sets the result to false if the first value is not greater than to the second value.
Gt(t, 2, 1) // success Gt(t, 3.14, 1.68) // success Gt(t, "BCD", "ABC") // success Gt(t, 2, 2) // fail Gt(t, 1, 2) // fail
func GtNow ¶ added in v1.0.0
GtNow compares the values and sets the result to false if the first value is not greater than to the second value. It will panic if they do not match the expected result.
GtNow(t, 2, 1) // success GtNow(t, 3.14, 1.68) // success GtNow(t, "BCD", "ABC") // success GtNow(t, 1, 2) // fail and terminate // never runs
func Gte ¶ added in v1.0.0
Gte compares the values and sets the result to false if the first value is not greater than or equal to the second value.
Gte(t, 2, 1) // success Gte(t, 3.14, 1.68) // success Gte(t, "BCD", "ABC") // success Gte(t, 2, 2) // success Gte(t, 1, 2) // fail
func GteNow ¶ added in v1.0.0
GteNow compares the values and sets the result to false if the first value is not greater than or equal to the second value. It will panic if they do not match the expected result.
GteNow(t, 2, 1) // success GteNow(t, 3.14, 1.68) // success GteNow(t, "BCD", "ABC") // success GteNow(t, 2, 2) // success GteNow(t, 1, 2) // fail and terminate // never runs
func HasPrefixString ¶ added in v0.1.7
HasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string does not have the prefix string.
HasPrefixString(t, "Hello world", "") // success HasPrefixString(t, "Hello world", "Hello") // success HasPrefixString(t, "Hello world", "world") // fail HasPrefixString(t, "Hello world", "hello") // fail
func HasPrefixStringNow ¶ added in v0.1.7
HasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string does not have the prefix string.
HasPrefixStringNow(t, "Hello world", "") // success HasPrefixStringNow(t, "Hello world", "Hello") // success HasPrefixStringNow(t, "Hello world", "hello") // fail and stop the execution // never runs
func HasSuffixString ¶ added in v0.1.7
HasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string does not have the suffix string.
HasSuffixString(t, "Hello world", "") // success HasSuffixString(t, "Hello world", "world") // success HasSuffixString(t, "Hello world", "World") // fail HasSuffixString(t, "Hello world", "hello") // fail
func HasSuffixStringNow ¶ added in v0.1.7
HasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string does not have the suffix string.
HasSuffixStringNow(t, "Hello world", "") // success HasSuffixStringNow(t, "Hello world", "world") // success HasSuffixStringNow(t, "Hello world", "World") // fail and stop the execution // never runs
func Lt ¶ added in v1.0.0
Lt compares the values and sets the result to false if the first value is not less than the second value.
Lt(t, 1, 2) // success Lt(t, 1.68, 3.14) // success Lt(t, "ABC", "BCD") // success Lt(t, 2, 2) // fail Lt(t, 2, 1) // fail
func LtNow ¶ added in v1.0.0
LtNow compares the values and sets the result to false if the first value is not less than the second value. It will panic if they do not match the expected result.
LtNow(t, 1, 2) // success LtNow(t, 1.68, 3.14) // success LtNow(t, "ABC", "BCD") // success LtNow(t, 2, 1) // fail and terminate // never runs
func Lte ¶ added in v1.0.0
Lte compares the values and sets the result to false if the first value is not less than or equal to the second value.
Lte(t, 1, 2) // success Lte(t, 1.68, 3.14) // success Lte(t, "ABC", "BCD") // success Lte(t, 2, 2) // success Lte(t, 2, 1) // fail
func LteNow ¶ added in v1.0.0
LteNow compares the values and sets the result to false if the first value is not less than or equal to the second value. It will panic if they do not match the expected result.
LteNow(t, 1, 2) // success LteNow(t, 1.68, 3.14) // success LteNow(t, "ABC", "BCD") // success LteNow(t, 2, 2) // success LteNow(t, 2, 1) // fail and terminate // never runs
func MapHasKey ¶ added in v0.2.1
MapHasKey tests whether the map contains the specified key or not, it will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.
assertion.MapHasKey(map[string]int{"a":1}, "a") // success assertion.MapHasKey(map[string]int{"a":1}, "b") // fail assertion.MapHasKey(map[string]int{"a":1}, 1) // fail
func MapHasKeyNow ¶ added in v0.2.1
MapHasKeyNow tests whether the map contains the specified key or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.
assertion.MapHasKeyNow(map[string]int{"a":1}, "a") // success assertion.MapHasKeyNow(map[string]int{"a":1}, "b") // fail and terminate // never run
func MapHasValue ¶ added in v0.2.1
MapHasValue tests whether the map contains the specified value or not, it will fail if the map does not contain the value, or the type of the value cannot assign to the type of the values of the map.
assertion.MapHasValue(map[string]int{"a":1}, 1) // success assertion.MapHasValue(map[string]int{"a":1}, 2) // fail assertion.MapHasValue(map[string]int{"a":1}, "a") // fail
func MapHasValueNow ¶ added in v0.2.1
MapHasValueNow tests whether the map contains the specified value or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the value, or the type of the value cannot assign to the type of the value of the map.
assertion.MapHasValueNow(map[string]int{"a":1}, 1) // success assertion.MapHasValueNow(map[string]int{"a":1}, 2) // fail and terminate // never run
func Match ¶ added in v0.1.5
Match tests whether the string matches the regular expression or not.
pattern := regexp.MustCompile(`^https?:\/\/`) Match(t, "http://example.com", pattern) // success Match(t, "example.com", pattern) // fail
func MatchNow ¶ added in v0.1.5
MatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if it does not match.
pattern := regexp.MustCompile(`^https?:\/\/`) MatchNow(t, "http://example.com", pattern) // success MatchNow(t, "example.com", pattern) // fail and terminate // never run
func MatchString ¶ added in v0.1.5
MatchString will compile the pattern and test whether the string matches the regular expression or not. It will panic if the pattern is not a valid regular expression.
MatchString(t, "http://example.com", `^https?:\/\/`) // success MatchString(t, "example.com", `^https?:\/\/`) // fail
func MatchStringNow ¶ added in v0.1.5
MatchStringNow will compile the pattern and test whether the string matches the regular expression or not. It will terminate the execution if it does not match, and it will panic if the pattern is not a valid regular expression.
MatchStringNow(t, "http://example.com", `^https?:\/\/`) // success MatchStringNow(t, "example.com", `^https?:\/\/`) // fail and terminate // never run
func Nil ¶ added in v0.1.1
Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
var err error // nil Nil(t, err) // success err = errors.New("some error") Nil(t, err) // fail
func NilNow ¶ added in v0.1.2
NilNow tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
This function will set the result to fail, and stop the execution if the value is not nil.
var err error // nil NilNow(t, err) // success err = errors.New("some error") NilNow(t, err) // fail and terminate // never run
func NotContainsElement ¶ added in v0.2.0
NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.
assertion.NotContainsElement([]int{1, 2, 3}, 4) // success assertion.NotContainsElement([]int{1, 2, 3}, 0) // success assertion.NotContainsElement([]int{1, 2, 3}, 1) // fail
func NotContainsElementNow ¶ added in v0.2.0
NotContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.
assertion.NotContainsElementNow([]int{1, 2, 3}, 4) // success assertion.NotContainsElementNow([]int{1, 2, 3}, 0) // success assertion.NotContainsElementNow([]int{1, 2, 3}, 1) // fail and stop the execution // never runs
func NotContainsString ¶ added in v0.1.7
NotContainsString tests whether the string contains the substring or not, and it set the result to fail if the string contains the substring.
NotContainsString(t, "Hello world", "") // fail NotContainsString(t, "Hello world", "Hello") // fail NotContainsString(t, "Hello world", "world") // fail NotContainsString(t, "Hello world", "hello") // success
func NotContainsStringNow ¶ added in v0.1.7
NotContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string contains the substring.
NotContainsStringNow(t, "Hello world", "hello") // success NotContainsStringNow(t, "Hello world", "Hello") // fail and stop the execution // never runs
func NotDeepEqual ¶
NotDeepEqual tests the deep inequality between actual and expected parameters. It'll set the result to fail if they are deeply equal, but it doesn't stop the execution.
NotDeepEqual(t, 1, 0) // success NotDeepEqual(t, 1, int64(1)) // success NotDeepEqual(t, 1, 1) // fail NotDeepEqual(t, "ABC", "ABC") // fail
func NotDeepEqualNow ¶ added in v0.1.2
NotDeepEqualNow tests the deep inequality between actual and expected parameters, and it'll stop the execution if they are deeply equal.
NotDeepEqual(t, 1, 0) // success NotDeepEqual(t, 1, int64(1)) // success NotDeepEqual(t, "ABC", "ABC") // fail and terminate // never run
func NotEqual ¶ added in v0.1.5
NotEqual tests the inequality between actual and expected parameters. It'll set the result to fail if they are equal, but it doesn't stop the execution.
NotEqual(t, 1, 0) // success NotEqual(t, "ABC", "CBA") // success NotEqual(t, 1, uint64(1)) // success NotEqual(t, 1, 1) // fail NotEqual(t, "ABC", "ABC") // fail NotEqual(t, 1, int64(1)) // fail
func NotEqualNow ¶ added in v0.1.5
NotEqualNow tests the inequality between actual and expected parameters, and it'll stop the execution if they are equal.
NotEqualNow(t, 1, 0) // success NotEqualNow(t, "ABC", "CBA") // success NotEqualNow(t, 1, 1) // fail and terminate // never run
func NotHasPrefixString ¶ added in v0.1.7
NotHasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string have the prefix string.
NotHasPrefixString(t, "Hello world", "hello") // success NotHasPrefixString(t, "Hello world", "world") // success NotHasPrefixString(t, "Hello world", "") // fail NotHasPrefixString(t, "Hello world", "Hello") // fail
func NotHasPrefixStringNow ¶ added in v0.1.7
NotHasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string have the prefix string.
NotHasPrefixStringNow(t, "Hello world", "hello") // success NotHasPrefixStringNow(t, "Hello world", "world") // success NotHasPrefixStringNow(t, "Hello world", "Hello") // fail and stop the execution // never runs
func NotHasSuffixString ¶ added in v0.1.7
NotHasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string have the suffix string.
NotHasSuffixString(t, "Hello world", "Hello") // success NotHasSuffixString(t, "Hello world", "World") // success NotHasSuffixString(t, "Hello world", "") // fail NotHasSuffixString(t, "Hello world", "world") // fail
func NotHasSuffixStringNow ¶ added in v0.1.7
NotHasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string have the suffix string.
NotHasSuffixStringNow(t, "Hello world", "hello") // success NotHasSuffixStringNow(t, "Hello world", "World") // success NotHasSuffixStringNow(t, "Hello world", "world") // fail and stop the execution // never runs
func NotMapHasKey ¶ added in v0.2.1
NotMapHasKey tests whether the map contains the specified key or not, it will fail if the map contain the key. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.
assertion.NotMapHasKey(map[string]int{"a":1}, "b") // success assertion.NotMapHasKey(map[string]int{"a":1}, 1) // success assertion.NotMapHasKey(map[string]int{"a":1}, "a") // fail
func NotMapHasKeyNow ¶ added in v0.2.1
NotMapHasKeyNow tests whether the map contains the specified key or not, it will fail if the map contain the key, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.
assertion.NotMapHasKeyNow(map[string]int{"a":1}, "b") // success assertion.NotMapHasKeyNow(map[string]int{"a":1}, 1) // success assertion.NotMapHasKeyNow(map[string]int{"a":1}, "a") // fail and terminate // never run
func NotMapHasValue ¶ added in v0.2.1
NotMapHasValue tests whether the map contains the specified value or not, it will fail if the map contain the value. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.
assertion.NotMapHasValue(map[string]int{"a":1}, 2) // success assertion.NotMapHasValue(map[string]int{"a":1}, "a") // success assertion.NotMapHasValue(map[string]int{"a":1}, 1) // fail
func NotMapHasValueNow ¶ added in v0.2.1
NotMapHasValueNow tests whether the map contains the specified value or not, it will fail if the map contain the value, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.
assertion.NotMapHasValueNow(map[string]int{"a":1}, 2) // success assertion.NotMapHasValueNow(map[string]int{"a":1}, "a") // success assertion.NotMapHasValueNow(map[string]int{"a":1}, 1) // fail and terminate // never run
func NotMatch ¶ added in v0.1.5
NotMatch tests whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern.
pattern := regexp.MustCompile(`^https?:\/\/`) NotMatch(t, "example.com", pattern) // success NotMatch(t, "http://example.com", pattern) // fail
func NotMatchNow ¶ added in v0.1.5
NotMatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if the string matches the pattern.
pattern := regexp.MustCompile(`^https?:\/\/`) NotMatchNow(t, "example.com", pattern) // success NotMatchNow(t, "http://example.com", pattern) // fail and terminate // never run
func NotMatchString ¶ added in v0.1.5
MatchString will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will also panic if the pattern is not a valid regular expression.
NotMatchString(t, "example.com", `^https?:\/\/`) // success NotMatchString(t, "http://example.com", `^https?:\/\/`) // fail
func NotMatchStringNow ¶ added in v0.1.5
NotMatchStringNow will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will terminate the execution if the string matches the pattern, and it will panic if the pattern is not a valid regular expression.
NotMatchStringNow(t, "example.com", `^https?:\/\/`) // success NotMatchStringNow(t, "http://example.com", `^https?:\/\/`) // fail and terminate // never run
func NotNil ¶ added in v0.1.1
NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
var err error // nil NotNil(t, err) // fail err = errors.New("some error") NotNil(t, err) // success
func NotNilNow ¶ added in v0.1.2
NotNilNow tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
This function will set the result to fail, and stop the execution if the value is nil.
var err error = errors.New("some error") NotNilNow(t, err) // success err = nil NotNilNow(t, err) // fail and terminate // never run
func NotPanic ¶
NotPanic asserts that the function fn does not panic, and it'll set the result to fail if the function panic.
NotPanic(t, func() { // no panic }) // success NotPanic(t, func() { panic("some error") }) // fail
func NotPanicNow ¶ added in v0.1.2
NotPanicNow asserts that the function fn does not panic. It'll set the result to fail if the function panic, and it also stops the execution.
NotPanicNow(t, func() { // no panic }) // success NotPanicNow(t, func() { panic("some error") }) // fail and terminate // never run
func NotTrue ¶ added in v0.1.4
NotTrue tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
NotTrue(t, 0) // success NotTrue(t, "") // success NotTrue(t, 1) // fail NotTrue(t, "test") // fail
func NotTrueNow ¶ added in v0.1.4
NotTrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
The function will stop the execution if the value is truthy.
NotTrueNow(t, 0) // success NotTrueNow(t, "") // success NotTrueNow(t, "test") // fail and terminate // never run
func Panic ¶
Panic expects the function fn to panic, and it'll set the result to fail if the function doesn't panic.
Panic(t, func() { panic("some error") }) // success Panic(t, func() { // no panic }) // fail
func PanicNow ¶ added in v0.1.2
PanicNow expects the function fn to panic. It'll set the result to fail if the function doesn't panic, and stop the execution.
PanicNow(t, func() { panic("some error") }) // success PanicNow(t, func() { // no panic }) // fail // never run
func True ¶ added in v0.1.4
True tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
True(t, 1) // success True(t, "test") // success True(t, 0) // fail True(t, "") // fail
func TrueNow ¶ added in v0.1.4
TrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
The function will stop the execution if the value is falsy.
TrueNow(t, 1) // success TrueNow(t, "test") // success TrueNow(t, "") // fail and terminate // never run
Types ¶
type Assertion ¶
Assertion is the extension of the Go builtin `testing.T`.
Please do not create an Assertion instance without the New function, every assertion function will panic if no inner testing.T set.
func New ¶
New returns an assertion instance for verifying invariants.
assertion := assert.New(t) assertion.Equal(actual, expect) // ...
func (*Assertion) ContainsElement ¶ added in v0.2.0
NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.
assertion.ContainsElement([]int{1, 2, 3}, 1) // success assertion.ContainsElement([]int{1, 2, 3}, 3) // success assertion.ContainsElement([]int{1, 2, 3}, 4) // fail
func (*Assertion) ContainsElementNow ¶ added in v0.2.0
ContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.
assertion.ContainsElementNow([]int{1, 2, 3}, 1) // success assertion.ContainsElementNow([]int{1, 2, 3}, 3) // success assertion.ContainsElementNow([]int{1, 2, 3}, 4) // fail and stop the execution // never runs
func (*Assertion) ContainsString ¶ added in v0.1.7
ContainsString tests whether the string contains the substring or not, and it set the result to fail if the string does not contains the substring.
assertion.ContainsString("Hello world", "") // success assertion.ContainsString("Hello world", "Hello") // success assertion.ContainsString("Hello world", "world") // success assertion.ContainsString("Hello world", "hello") // fail
func (*Assertion) ContainsStringNow ¶ added in v0.1.7
ContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string does not contains the substring.
assertion.ContainsStringNow("Hello world", "") // success assertion.ContainsStringNow("Hello world", "Hello") // success assertion.ContainsStringNow("Hello world", "world") // success assertion.ContainsStringNow("Hello world", "hello") // fail and stop the execution // never runs
func (*Assertion) DeepEqual ¶
DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to fail if they are not deeply equal, and it doesn't stop the execution.
assertion.DeepEqual(1, 1) // success assertion.DeepEqual("ABC", "ABC") // success assertion.DeepEqual(1, 0) // fail assertion.DeepEqual(1, int64(1)) // fail
func (*Assertion) DeepEqualNow ¶ added in v0.1.2
DeepEqualNow tests the deep equality between actual and expect parameters, and it'll stop the execution if they are not deeply equal.
assertion.DeepEqualNow(1, 1) // success assertion.DeepEqualNow("ABC", "ABC") // success assertion.DeepEqualNow(1, int64(1)) // fail and terminate // never run
func (*Assertion) Equal ¶ added in v0.1.5
Equal tests the equality between actual and expect parameters. It'll set the result to fail if they are not equal, and it doesn't stop the execution.
assertion.Equal(1, 1) // success assertion.Equal("ABC", "ABC") // success assertion.Equal(1, int64(1)) // success assertion.Equal(1, uint64(1)) // fail assertion.Equal(1, 0) // fail
func (*Assertion) EqualNow ¶ added in v0.1.5
EqualNow tests the equality between actual and expect parameters, and it'll stop the execution if they are not equal.
assertion.EqualNow(1, 1) // success assertion.EqualNow("ABC", "ABC") // success assertion.EqualNow(1, int64(1)) // success assertion.EqualNow(1, 0) // fail and terminate never run
func (*Assertion) Gt ¶ added in v1.0.0
Gt compares the values and sets the result to false if the first value is not greater than to the second value.
a.Gt(2, 1) // success a.Gt(3.14, 1.68) // success a.Gt("BCD", "ABC") // success a.Gt(2, 2) // fail a.Gt(1, 2) // fail
func (*Assertion) GtNow ¶ added in v1.0.0
GtNow compares the values and sets the result to false if the first value is not greater than to the second value. It will panic if they do not match the expected result.
a.GtNow(2, 1) // success a.GtNow(3.14, 1.68) // success a.GtNow("BCD", "ABC") // success a.GtNow(1, 2) // fail and terminate // never runs
func (*Assertion) Gte ¶ added in v1.0.0
Gte compares the values and sets the result to false if the first value is not greater than or equal to the second value.
a.Gte(2, 1) // success a.Gte(3.14, 1.68) // success a.Gte("BCD", "ABC") // success a.Gte(2, 2) // success a.Gte(1, 2) // fail
func (*Assertion) GteNow ¶ added in v1.0.0
GteNow compares the values and sets the result to false if the first value is not greater than or equal to the second value. It will panic if they do not match the expected result.
a.GteNow(2, 1) // success a.GteNow(3.14, 1.68) // success a.GteNow("BCD", "ABC") // success a.GteNow(2, 2) // success a.GteNow(1, 2) // fail and terminate // never runs
func (*Assertion) HasPrefixString ¶ added in v0.1.7
HasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string does not have the prefix string.
assertion.HasPrefixString("Hello world", "") // success assertion.HasPrefixString("Hello world", "Hello") // success assertion.HasPrefixString("Hello world", "world") // fail assertion.HasPrefixString("Hello world", "hello") // fail
func (*Assertion) HasPrefixStringNow ¶ added in v0.1.7
HasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string does not have the prefix string.
assertion.HasPrefixStringNow("Hello world", "") // success assertion.HasPrefixStringNow("Hello world", "Hello") // success assertion.HasPrefixStringNow("Hello world", "hello") // fail and stop the execution // never runs
func (*Assertion) HasSuffixString ¶ added in v0.1.7
HasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string does not have the suffix string.
assertion.HasSuffixString("Hello world", "") // success assertion.HasSuffixString("Hello world", "world") // success assertion.HasSuffixString("Hello world", "World") // fail assertion.HasSuffixString("Hello world", "hello") // fail
func (*Assertion) HasSuffixStringNow ¶ added in v0.1.7
HasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string does not have the suffix string.
assertion.HasSuffixStringNow("Hello world", "") // success assertion.HasSuffixStringNow("Hello world", "world") // success assertion.HasSuffixStringNow("Hello world", "World") // fail and stop the execution // never runs
func (*Assertion) Lt ¶ added in v1.0.0
Lt compares the values and sets the result to false if the first value is not less than the second value.
a.Lt(1, 2) // success a.Lt(1.68, 3.14) // success a.Lt("ABC", "BCD") // success a.Lt(2, 2) // fail a.Lt(2, 1) // fail
func (*Assertion) LtNow ¶ added in v1.0.0
LtNow compares the values and sets the result to false if the first value is not less than the second value. It will panic if they do not match the expected result.
a.LtNow(1, 2) // success a.LtNow(1.68, 3.14) // success a.LtNow("ABC", "BCD") // success a.LtNow(2, 1) // fail and terminate // never runs
func (*Assertion) Lte ¶ added in v1.0.0
Lte compares the values and sets the result to false if the first value is not less than or equal to the second value.
a.Lte(1, 2) // success a.Lte(1.68, 3.14) // success a.Lte("ABC", "BCD") // success a.Lte(2, 2) // success a.Lte(2, 1) // fail
func (*Assertion) LteNow ¶ added in v1.0.0
LteNow compares the values and sets the result to false if the first value is not less than or equal to the second value. It will panic if they do not match the expected result.
a.LteNow(1, 2) // success a.LteNow(1.68, 3.14) // success a.LteNow("ABC", "BCD") // success a.LteNow(2, 2) // success a.LteNow(2, 1) // fail and terminate // never runs
func (*Assertion) MapHasKey ¶ added in v0.2.1
MapHasKey tests whether the map contains the specified key or not, it will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.
assertion.MapHasKey(map[string]int{"a":1}, "a") // success assertion.MapHasKey(map[string]int{"a":1}, "b") // fail assertion.MapHasKey(map[string]int{"a":1}, 1) // fail
func (*Assertion) MapHasKeyNow ¶ added in v0.2.1
MapHasKeyNow tests whether the map contains the specified key or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.
assertion.MapHasKeyNow(map[string]int{"a":1}, "a") // success assertion.MapHasKeyNow(map[string]int{"a":1}, "b") // fail and terminate // never run
func (*Assertion) MapHasValue ¶ added in v0.2.1
MapHasValue tests whether the map contains the specified value or not, it will fail if the map does not contain the value, or the type of the value cannot assign to the type of the values of the map.
assertion.MapHasValue(map[string]int{"a":1}, 1) // success assertion.MapHasValue(map[string]int{"a":1}, 2) // fail assertion.MapHasValue(map[string]int{"a":1}, "a") // fail
func (*Assertion) MapHasValueNow ¶ added in v0.2.1
MapHasValueNow tests whether the map contains the specified value or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the value, or the type of the value cannot assign to the type of the value of the map.
assertion.MapHasValueNow(map[string]int{"a":1}, 1) // success assertion.MapHasValueNow(map[string]int{"a":1}, 2) // fail and terminate // never run
func (*Assertion) Match ¶ added in v0.1.5
Match tests whether the string matches the regular expression or not.
pattern := regexp.MustCompile(`^https?:\/\/`) assertion.Match("http://example.com", pattern) // success assertion.Match("example.com", pattern) // fail
func (*Assertion) MatchNow ¶ added in v0.1.5
MatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if it does not match.
pattern := regexp.MustCompile(`^https?:\/\/`) assertion.MatchNow("http://example.com", pattern) // success assertion.MatchNow("example.com", pattern) // fail and terminate // never run
func (*Assertion) MatchString ¶ added in v0.1.5
MatchString will compile the pattern and test whether the string matches the regular expression or not. It will panic if the pattern is not a valid regular expression.
assertion.MatchString("http://example.com", `^https?:\/\/`) // success assertion.MatchString("example.com", `^https?:\/\/`) // fail
func (*Assertion) MatchStringNow ¶ added in v0.1.5
MatchStringNow will compile the pattern and test whether the string matches the regular expression or not. It will terminate the execution if it does not match, and it will panic if the pattern is not a valid regular expression.
assertion.MatchStringNow("http://example.com", `^https?:\/\/`) // success assertion.MatchStringNow("example.com", `^https?:\/\/`) // fail and terminate // never run
func (*Assertion) Nil ¶ added in v0.1.1
Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
var err error // nil assertion.Nil(err) // success err = errors.New("some error") assertion.Nil(err) // fail
func (*Assertion) NilNow ¶ added in v0.1.2
NilNow tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
This function will set the result to fail, and stop the execution if the value is not nil.
var err error // nil assertion.NilNow(err) // success err = errors.New("some error") assertion.NilNow(err) // fail and terminate // never run
func (*Assertion) NotContainsElement ¶ added in v0.2.0
NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.
assertion.NotContainsElement([]int{1, 2, 3}, 4) // success assertion.NotContainsElement([]int{1, 2, 3}, 0) // success assertion.NotContainsElement([]int{1, 2, 3}, 1) // fail
func (*Assertion) NotContainsElementNow ¶ added in v0.2.0
NotContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.
assertion.NotContainsElementNow([]int{1, 2, 3}, 4) // success assertion.NotContainsElementNow([]int{1, 2, 3}, 0) // success assertion.NotContainsElementNow([]int{1, 2, 3}, 1) // fail and stop the execution // never runs
func (*Assertion) NotContainsString ¶ added in v0.1.7
NotContainsString tests whether the string contains the substring or not, and it set the result to fail if the string contains the substring.
assertion.NotContainsString("Hello world", "hello") // success assertion.NotContainsString("Hello world", "") // fail assertion.NotContainsString("Hello world", "Hello") // fail assertion.NotContainsString("Hello world", "world") // fail
func (*Assertion) NotContainsStringNow ¶ added in v0.1.7
NotContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string contains the substring.
assertion.NotContainsStringNow("Hello world", "hello") // success assertion.NotContainsStringNow("Hello world", "Hello") // fail and stop the execution // never runs
func (*Assertion) NotDeepEqual ¶
NotDeepEqual tests the deep inequality between actual and expected parameters. It'll set the result to fail if they are deeply equal, but it doesn't stop the execution.
assertion.NotDeepEqual(1, 0) // success assertion.NotDeepEqual(1, int64(1)) // success assertion.NotDeepEqual(1, 1) // fail assertion.NotDeepEqual("ABC", "ABC") // fail
func (*Assertion) NotDeepEqualNow ¶ added in v0.1.2
NotDeepEqualNow tests the deep inequality between actual and expected parameters, and it'll stop the execution if they are deeply equal.
assertion.NotDeepEqual1, 0) // success assertion.NotDeepEqual1, int64(1)) // success assertion.NotDeepEqual"ABC", "ABC") // fail and terminate // never run
func (*Assertion) NotEqual ¶ added in v0.1.5
NotEqual tests the inequality between actual and expected parameters. It'll set the result to fail if they are equal, but it doesn't stop the execution.
assertion.NotEqual(1, 0) // success assertion.NotEqual("ABC", "CBA") // success assertion.NotEqual(1, uint64(1)) // success assertion.NotEqual(1, 1) // fail assertion.NotEqual("ABC", "ABC") // fail assertion.NotEqual(1, int64(1)) // fail
func (*Assertion) NotEqualNow ¶ added in v0.1.5
NotEqualNow tests the inequality between actual and expected parameters, and it'll stop the execution if they are equal.
assertion.NotEqualNow(1, 0) // success assertion.NotEqualNow("ABC", "CBA") // success assertion.NotEqualNow(1, 1) // fail and terminate // never run
func (*Assertion) NotHasPrefixString ¶ added in v0.1.7
NotHasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string have the prefix string.
assertion.NotHasPrefixString("Hello world", "hello") // success assertion.NotHasPrefixString("Hello world", "world") // success assertion.NotHasPrefixString("Hello world", "") // fail assertion.NotHasPrefixString("Hello world", "Hello") // fail
func (*Assertion) NotHasPrefixStringNow ¶ added in v0.1.7
NotHasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string have the prefix string.
assertion.NotHasPrefixStringNow("Hello world", "hello") // success assertion.NotHasPrefixStringNow("Hello world", "world") // success assertion.NotHasPrefixStringNow("Hello world", "Hello") // fail and stop the execution // never runs
func (*Assertion) NotHasSuffixString ¶ added in v0.1.7
NotHasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string have the suffix string.
assertion.NotHasSuffixString("Hello world", "Hello") // success assertion.NotHasSuffixString("Hello world", "World") // success assertion.NotHasSuffixString("Hello world", "") // fail assertion.NotHasSuffixString("Hello world", "world") // fail
func (*Assertion) NotHasSuffixStringNow ¶ added in v0.1.7
NotHasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string have the suffix string.
assertion.NotHasSuffixStringNow("Hello world", "hello") // success assertion.NotHasSuffixStringNow("Hello world", "World") // success assertion.NotHasSuffixStringNow("Hello world", "world") // fail and stop the execution // never runs
func (*Assertion) NotMapHasKey ¶ added in v0.2.1
NotMapHasKey tests whether the map contains the specified key or not, it will fail if the map contain the key. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.
assertion.NotMapHasKey(map[string]int{"a":1}, "b") // success assertion.NotMapHasKey(map[string]int{"a":1}, 1) // success assertion.NotMapHasKey(map[string]int{"a":1}, "a") // fail
func (*Assertion) NotMapHasKeyNow ¶ added in v0.2.1
NotMapHasKeyNow tests whether the map contains the specified key or not, it will fail if the map contain the key, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.
assertion.NotMapHasKeyNow(map[string]int{"a":1}, "b") // success assertion.NotMapHasKeyNow(map[string]int{"a":1}, 1) // success assertion.NotMapHasKeyNow(map[string]int{"a":1}, "a") // fail and terminate // never run
func (*Assertion) NotMapHasValue ¶ added in v0.2.1
NotMapHasValue tests whether the map contains the specified value or not, it will fail if the map contain the value. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.
assertion.NotMapHasValue(map[string]int{"a":1}, 2) // success assertion.NotMapHasValue(map[string]int{"a":1}, "a") // success assertion.NotMapHasValue(map[string]int{"a":1}, 1) // fail
func (*Assertion) NotMapHasValueNow ¶ added in v0.2.1
NotMapHasValueNow tests whether the map contains the specified value or not, it will fail if the map contain the value, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.
assertion.NotMapHasValueNow(map[string]int{"a":1}, 2) // success assertion.NotMapHasValueNow(map[string]int{"a":1}, "a") // success assertion.NotMapHasValueNow(map[string]int{"a":1}, 1) // fail and terminate // never run
func (*Assertion) NotMatch ¶ added in v0.1.5
NotMatch tests whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern.
pattern := regexp.MustCompile(`^https?:\/\/`) assertion.NotMatch("example.com", pattern) // success assertion.NotMatch("http://example.com", pattern) // fail
func (*Assertion) NotMatchNow ¶ added in v0.1.5
NotMatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if the string matches the pattern.
pattern := regexp.MustCompile(`^https?:\/\/`) assertion.NotMatchNow("example.com", pattern) // success assertion.NotMatchNow("http://example.com", pattern) // fail and terminate // never run
func (*Assertion) NotMatchString ¶ added in v0.1.5
MatchString will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will also panic if the pattern is not a valid regular expression.
assertion.NotMatchString("example.com", `^https?:\/\/`) // success assertion.NotMatchString("http://example.com", `^https?:\/\/`) // fail
func (*Assertion) NotMatchStringNow ¶ added in v0.1.5
NotMatchStringNow will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will terminate the execution if the string matches the pattern, and it will panic if the pattern is not a valid regular expression.
assertion.NotMatchStringNow("example.com", `^https?:\/\/`) // success assertion.NotMatchStringNow("http://example.com", `^https?:\/\/`) // fail and terminate // never run
func (*Assertion) NotNil ¶ added in v0.1.1
NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
var err error // nil assertion.NotNil(err) // fail err = errors.New("some error") assertion.NotNil(err) // success
func (*Assertion) NotNilNow ¶ added in v0.1.2
NotNilNow tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
This function will set the result to fail, and stop the execution if the value is nil.
var err error = errors.New("some error") assertion.NotNilNow(err) // success err = nil assertion.NotNilNow(err) // fail and terminate // never run
func (*Assertion) NotPanic ¶
NotPanic asserts that the function fn does not panic, and it'll set the result to fail if the function panic.
assertion.NotPanic(func() { // no panic }) // success assertion.NotPanic(func() { panic("some error") }) // fail
func (*Assertion) NotPanicNow ¶ added in v0.1.2
NotPanicNow asserts that the function fn does not panic. It'll set the result to fail if the function panic, and it also stops the execution.
assertion.NotPanicNow(func() { // no panic }) // success assertion.NotPanicNow(func() { panic("some error") }) // fail and terminate // never run
func (*Assertion) NotTrue ¶ added in v0.1.4
NotTrue tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
assertion.NotTrue(0) // success assertion.NotTrue("") // success assertion.NotTrue(1) // fail assertion.NotTrue("test") // fail
func (*Assertion) NotTrueNow ¶ added in v0.1.4
NotTrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
The function will stop the execution if the value is truthy.
assertion.NotTrueNow(0) // success assertion.NotTrueNow("") // success assertion.NotTrueNow("test") // fail and terminate // never run
func (*Assertion) Panic ¶
Panic expects the function fn to panic, and it'll set the result to fail if the function doesn't panic.
assertion.Panic(func() { panic("some error") }) // success assertion.Panic(func() { // no panic }) // fail
func (*Assertion) PanicNow ¶ added in v0.1.2
PanicNow expects the function fn to panic. It'll set the result to fail if the function doesn't panic, and stop the execution.
assertion.PanicNow(func() { panic("some error") }) // success assertion.PanicNow(func() { // no panic }) // fail // never run
func (*Assertion) Run ¶ added in v0.1.1
Run runs f as a subtest of a called name. It runs f in a separate goroutine and blocks until f returns or calls a.Parallel to become a parallel test. Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
Run may be called simultaneously from multiple goroutines, but all such calls must return before the outer test function for a returns.
assertion := assert.New(t) assertion.Run("SubTest", func (a *assert.Assertion) bool { // TODO... })
func (*Assertion) True ¶ added in v0.1.4
True tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
assertion.True(1) // success assertion.True("test") // success assertion.True(0) // fail assertion.True("") // fail
func (*Assertion) TrueNow ¶ added in v0.1.4
TrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.
The function will stop the execution if the value is falsy.
assertion.TrueNow(1) // success assertion.TrueNow("test") // success assertion.TrueNow("") // fail and terminate // never run
type AssertionError ¶
type AssertionError struct {
// contains filtered or unexported fields
}
AssertionError indicates the failure of an assertion.
func (AssertionError) Error ¶
func (err AssertionError) Error() string
Error returns the message of the error.