Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
adamluzsi committed Jul 4, 2023
1 parent 48ee9c5 commit 8f97729
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions assert/Asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,23 @@ func (a Asserter) NotPanic(blk func(), msg ...any) {
// - value.IsEqual(oth T) (bool, error)
// - value.Equal(oth T) bool
// - value.Equal(oth T) (bool, error)
func (a Asserter) Equal(expected, actually any, msg ...any) {
func (a Asserter) Equal(v, oth any, msg ...any) {
a.TB.Helper()
const method = "Equal"

if a.checkTypeEquality(method, expected, actually, msg) {
if a.checkTypeEquality(method, v, oth, msg) {
return
}

if a.eq(expected, actually) {
if a.eq(v, oth) {
return
}

a.TB.Log(fmterror.Message{
Method: method,
Message: msg,
}.String())
a.TB.Logf("\n\n%s", DiffFunc(expected, actually))
a.TB.Logf("\n\n%s", DiffFunc(v, oth))
a.Fail()
}

Expand Down Expand Up @@ -208,16 +208,16 @@ func (a Asserter) NotEqual(v, oth any, msg ...any) {
}.String())
}

func (a Asserter) checkTypeEquality(method string, expected any, actually any, msg []any) (failed bool) {
func (a Asserter) checkTypeEquality(method string, v any, oth any, msg []any) (failed bool) {
a.TB.Helper()
var (
expectedType = reflect.TypeOf(expected)
actualType = reflect.TypeOf(actually)
vType = reflect.TypeOf(v)
othType = reflect.TypeOf(oth)
)
if expectedType == nil || actualType == nil {
if vType == nil || othType == nil {
return false
}
if expectedType == actualType {
if vType == othType {
return false
}
toRawString := func(rt reflect.Type) fmterror.Raw {
Expand All @@ -232,12 +232,12 @@ func (a Asserter) checkTypeEquality(method string, expected any, actually any, m
Message: msg,
Values: []fmterror.Value{
{
Label: "expected type",
Value: toRawString(expectedType),
Label: "type",
Value: toRawString(vType),
},
{
Label: "actual type",
Value: toRawString(actualType),
Label: "other value's type",
Value: toRawString(othType),
},
},
}.String())
Expand Down

0 comments on commit 8f97729

Please sign in to comment.