zk/util/assert/assert.go

30 lines
737 B
Go
Raw Normal View History

2020-12-25 19:25:52 +00:00
package assert
import (
"reflect"
"testing"
)
func Nil(t *testing.T, value interface{}) {
if !isNil(value) {
2020-12-26 15:53:04 +00:00
t.Errorf("Expected `%v` (type %v) to be nil", value, reflect.TypeOf(value))
2020-12-25 19:25:52 +00:00
}
}
func NotNil(t *testing.T, value interface{}) {
if isNil(value) {
2020-12-26 15:53:04 +00:00
t.Errorf("Expected `%v` (type %v) to not be nil", value, reflect.TypeOf(value))
2020-12-25 19:25:52 +00:00
}
}
func isNil(value interface{}) bool {
return value == nil ||
(reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil())
}
2020-12-26 13:49:20 +00:00
func Equal(t *testing.T, actual, expected interface{}) {
if !reflect.DeepEqual(actual, expected) {
2020-12-26 15:53:04 +00:00
t.Errorf("Received `%+v` (type %v), expected `%+v` (type %v)", actual, reflect.TypeOf(actual), expected, reflect.TypeOf(expected))
2020-12-25 19:25:52 +00:00
}
}