aboutsummaryrefslogtreecommitdiff
path: root/lib/test
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-03-19 15:19:04 +0700
committerShulhan <m.shulhan@gmail.com>2020-03-20 03:34:25 +0700
commit9ec24a017e26239145d8abb02b801f243b505fa9 (patch)
treed5b17f04c7e521842bd38147ac3ed76cc46a8075 /lib/test
parent0ebbaa2d1cb7d7b27f6993bb23642e428ff68649 (diff)
downloadpakakeh.go-9ec24a017e26239145d8abb02b801f243b505fa9.tar.xz
reflect: add function IsEqual that works with Equaler interface
The IsEqual() function is like reflect.DeepEqual but its check if a struct have method "IsEqual", if its exist it will call the method to compare the value.
Diffstat (limited to 'lib/test')
-rw-r--r--lib/test/test.go18
1 files changed, 3 insertions, 15 deletions
diff --git a/lib/test/test.go b/lib/test/test.go
index d94b7006..a4b5f04e 100644
--- a/lib/test/test.go
+++ b/lib/test/test.go
@@ -8,11 +8,10 @@
package test
import (
- "reflect"
"runtime"
"testing"
- libreflect "github.com/shuLhan/share/lib/reflect"
+ "github.com/shuLhan/share/lib/reflect"
)
func printStackTrace(t testing.TB, trace []byte) {
@@ -48,18 +47,7 @@ func printStackTrace(t testing.TB, trace []byte) {
// expectation and then terminate the test routine.
//
func Assert(t *testing.T, name string, exp, got interface{}, equal bool) {
- if exp == nil && got == nil && equal {
- return
- }
- if libreflect.IsNil(exp) && libreflect.IsNil(got) && equal {
- return
- }
- eq, ok := exp.(libreflect.Equaler)
- if ok && eq.IsEqual(got) == equal {
- return
- }
-
- if reflect.DeepEqual(exp, got) == equal {
+ if reflect.IsEqual(exp, got) == equal {
return
}
@@ -80,7 +68,7 @@ func Assert(t *testing.T, name string, exp, got interface{}, equal bool) {
// expectation and then terminate the test routine.
//
func AssertBench(b *testing.B, name string, exp, got interface{}, equal bool) {
- if reflect.DeepEqual(exp, got) == equal {
+ if reflect.IsEqual(exp, got) == equal {
return
}