package tool import ( "strings" "testing" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" ) type otherString string func (x otherString) Equal(y otherString) bool { return strings.EqualFold(string(x), string(y)) } func TestOptionAvoidEqualMethod(t *testing.T) { type myString otherString // This transformer converts otherString to myString, allowing Equal to use // other Options to determine equality. trans := cmp.Transformer("", func(in otherString) myString { return myString(in) }) x := []otherString{"foo", "bar", "baz"} y := []otherString{"fOO", "bAr", "Baz"} // Same as before, but with different case assert.True(t, cmp.Equal(x, y)) // Equal because of case-insensitivity assert.False(t, cmp.Equal(x, y, trans)) // Not equal because of more exact equality }