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

Function Comparer

cmp/options.go:355–365  ·  cmp/options.go::Comparer

Comparer returns an [Option] that determines whether two values are equal to each other. The comparer f must be a function "func(T, T) bool" and is implicitly filtered to input values assignable to T. If T is an interface, it is possible that f is called with two values of different concrete types

(f interface{})

Source from the content-addressed store, hash-verified

353// - Deterministic: equal(x, y) == equal(x, y)
354// - Pure: equal(x, y) does not modify x or y
355func Comparer(f interface{}) Option {
356 v := reflect.ValueOf(f)
357 if !function.IsType(v.Type(), function.Equal) || v.IsNil() {
358 panic(fmt.Sprintf("invalid comparer function: %T", f))
359 }
360 cm := &comparer{fnc: v}
361 if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 {
362 cm.typ = ti
363 }
364 return cm
365}
366
367type comparer struct {
368 core

Callers 15

comparerTestsFunction · 0.92
reporterTestsFunction · 0.92
project1TestsFunction · 0.92
project2TestsFunction · 0.92
project3TestsFunction · 0.92
project4TestsFunction · 0.92
ExampleOption_equalNaNsFunction · 0.92
ExampleOption_equalEmptyFunction · 0.92
TestOptionsFunction · 0.92

Calls 3

IsTypeFunction · 0.92
IsNilMethod · 0.80
TypeMethod · 0.65

Tested by 13

comparerTestsFunction · 0.74
reporterTestsFunction · 0.74
project1TestsFunction · 0.74
project2TestsFunction · 0.74
project3TestsFunction · 0.74
project4TestsFunction · 0.74
ExampleOption_equalNaNsFunction · 0.74
ExampleOption_equalEmptyFunction · 0.74
TestOptionsFunction · 0.74