diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-03-19 15:19:04 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-03-20 03:34:25 +0700 |
| commit | 9ec24a017e26239145d8abb02b801f243b505fa9 (patch) | |
| tree | d5b17f04c7e521842bd38147ac3ed76cc46a8075 /lib/test | |
| parent | 0ebbaa2d1cb7d7b27f6993bb23642e428ff68649 (diff) | |
| download | pakakeh.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.go | 18 |
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 } |
