aboutsummaryrefslogtreecommitdiff
path: root/lib/test
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-03-18 18:41:08 +0700
committerShulhan <m.shulhan@gmail.com>2020-03-20 03:34:25 +0700
commit0ebbaa2d1cb7d7b27f6993bb23642e428ff68649 (patch)
tree177f088c7abda4e9cd79ad336a7e2fdea49ebcf4 /lib/test
parent2955a465722a5d25bef76a45f1be5665e48ea543 (diff)
downloadpakakeh.go-0ebbaa2d1cb7d7b27f6993bb23642e428ff68649.tar.xz
test: check if exp implement reflect.Equaler
If the exp parameter implement the extended "reflect.Equaler" interface then it will use the method IsEqual() with "got" as parameter.
Diffstat (limited to 'lib/test')
-rw-r--r--lib/test/test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/test/test.go b/lib/test/test.go
index b48ab626..d94b7006 100644
--- a/lib/test/test.go
+++ b/lib/test/test.go
@@ -11,6 +11,8 @@ import (
"reflect"
"runtime"
"testing"
+
+ libreflect "github.com/shuLhan/share/lib/reflect"
)
func printStackTrace(t testing.TB, trace []byte) {
@@ -39,10 +41,24 @@ func printStackTrace(t testing.TB, trace []byte) {
// Assert will compare two interfaces: `exp` and `got` whether its same with
// `equal` value.
//
+// If `exp` implement the extended `reflect.Equaler`, then it will use the
+// method `IsEqual()` with `got` as parameter.
+//
// If comparison result is not same with `equal`, it will print the result and
// 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 {
return
}