deep icon indicating copy to clipboard operation
deep copied to clipboard

wrong comparison for slices types with Equal() method

Open skinass opened this issue 5 years ago • 1 comments

in commit https://github.com/go-test/deep/commit/929fce90938cb6eb75b23056d23a3bbc4e64b926 the check of Equal() function was moved under the reflect.Struct case. and here is an example why this is wrong: https://play.golang.org/p/AlgXufFrO1g

package main

import (
	"fmt"
	"net"
	"github.com/go-test/deep"
)

func main() {
	ipA := net.ParseIP("1.2.3.4")
	ipB := net.ParseIP("1.2.3.4").To4()
	
	fmt.Println(deep.Equal(ipA, ipB))
	
	fmt.Println(ipA.Equal(ipB))
}

ipA and ipB has different len of their slice inside, but they still represents the same ip. however deep.Equal() say there is a diff between ipA and ipB.

not only structs may have an Equal() method.

skinass avatar Aug 02 '19 13:08 skinass

Thanks for the bug report. I'll see if/how to generalize the test for an Equal method to cover all such cases.

daniel-nichter avatar Aug 04 '19 21:08 daniel-nichter