MCPcopy
hub / github.com/google/go-cmp / EquateComparable

Function EquateComparable

cmp/cmpopts/equate.go:166–179  ·  view source on GitHub ↗

EquateComparable returns a [cmp.Option] that determines equality of comparable types by directly comparing them using the == operator in Go. The types to compare are specified by passing a value of that type. This option should only be used on types that are documented as being safe for direct == co

(typs ...interface{})

Source from the content-addressed store, hash-verified

164// as being semantically safe to use with ==, while [time.Time] is documented
165// to discourage the use of == on time values.
166func EquateComparable(typs ...interface{}) cmp.Option {
167 types := make(typesFilter)
168 for _, typ := range typs {
169 switch t := reflect.TypeOf(typ); {
170 case !t.Comparable():
171 panic(fmt.Sprintf("%T is not a comparable Go type", typ))
172 case types[t]:
173 panic(fmt.Sprintf("%T is already specified", typ))
174 default:
175 types[t] = true
176 }
177 }
178 return cmp.FilterPath(types.filter, cmp.Comparer(equateAny))
179}
180
181type typesFilter map[reflect.Type]bool
182

Callers 1

TestOptionsFunction · 0.85

Calls 2

FilterPathFunction · 0.92
ComparerFunction · 0.92

Tested by 1

TestOptionsFunction · 0.68