Documentation
¶
Overview ¶
Package compare provides a value comparator.
Example ¶
type T struct {
String string
Int int
Map map[string]any
Slice []int
}
v1 := T{
String: "aaa",
Int: 1,
Map: map[string]any{
"a": "a",
"b": "b",
"c": "c",
},
Slice: []int{1, 2, 3},
}
v2 := T{
String: "bbb",
Int: 2,
Map: map[string]any{
"a": "z",
"b": 5,
"d": "c",
},
Slice: []int{1, 2, 4},
}
diff := Compare(v1, v2)
if len(diff) != 0 {
fmt.Print(diff)
}
Output: .String: string not equal v1 = aaa v2 = bbb .Int: int not equal v1 = 1 v2 = 2 .Map[a]: string not equal v1 = a v2 = z .Map[b]: type not equal v1 = string v2 = int .Map[c]: map key not defined v1 = true v2 = false .Map[d]: map key not defined v1 = false v2 = true .Slice[2]: int not equal v1 = 3 v2 = 4
Index ¶
- Variables
- func FilterTypes(typs ...reflect.Type) func(typ reflect.Type) bool
- type ArrayComparator
- type BoolComparator
- type ByTypeComparators
- type BytesComparator
- type CanInterfaceComparator
- type ChanComparator
- type CommonComparator
- type Comparator
- type CompareComparator
- type ComplexComparator
- type Difference
- type EqualComparator
- type FilterComparator
- type FloatComparator
- type FuncComparator
- type IntComparator
- type InterfaceComparator
- type KindComparator
- type MapComparator
- type MaxDepthComparator
- type Path
- type PathElem
- type PointerComparator
- type RecursionComparator
- type ReflectValueComparator
- type Result
- type SliceComparator
- type State
- type StringComparator
- type StructComparator
- type SupportChecker
- type SupportCheckerFunc
- type SupportCheckerValuesComparator
- type SupportComparator
- type UintComparator
- type UnsafePointerComparator
- type ValuesComparator
- type ValuesComparatorFunc
- type ValuesComparators
- type VisitedEntry
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultComparator atomic.Pointer[Comparator]
DefaultComparator is the default Comparator.
It uses DefaultValuesComparator.
var DefaultValuesComparator atomic.Pointer[CommonComparator]
DefaultValuesComparator is the default CommonComparator.
Functions ¶
Types ¶
type ArrayComparator ¶ added in v1.6.0
type ArrayComparator struct {
ValuesComparator
// MaxDifferences is the maximum number of different items to report.
// If reached, the comparison is stopped for the current array.
// Setting it to 0 disables it.
// Default: 10.
MaxDifferences int
}
ArrayComparator is a ValuesComparator for array values.
It should be created with NewArrayComparator.
func NewArrayComparator ¶ added in v1.6.0
func NewArrayComparator(vc ValuesComparator) *ArrayComparator
NewArrayComparator creates a new ArrayComparator.
func (*ArrayComparator) CompareValues ¶ added in v1.6.0
func (vc *ArrayComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*ArrayComparator) Supports ¶ added in v1.6.0
func (vc *ArrayComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type BoolComparator ¶ added in v1.6.0
type BoolComparator struct{}
BoolComparator is a ValuesComparator for bool values.
It should be created with NewBoolComparator.
func NewBoolComparator ¶ added in v1.6.0
func NewBoolComparator() *BoolComparator
NewBoolComparator creates a new BoolComparator.
func (*BoolComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*BoolComparator) Supports ¶ added in v1.6.0
func (vc *BoolComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type ByTypeComparators ¶ added in v1.6.0
type ByTypeComparators map[reflect.Type]ValuesComparator
ByTypeComparators selects a ValuesComparator by reflect.Type.
It should be created with NewByTypeComparators.
func NewByTypeComparators ¶ added in v1.6.0
func NewByTypeComparators() ByTypeComparators
NewByTypeComparators creates a new ByTypeComparators.
func (ByTypeComparators) CompareValues ¶ added in v1.6.0
func (vcs ByTypeComparators) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type BytesComparator ¶ added in v1.6.0
type BytesComparator struct{}
BytesComparator is a ValuesComparator for byte slice values ([]byte).
It should be created with NewBytesComparator.
func NewBytesComparator ¶ added in v1.6.0
func NewBytesComparator() *BytesComparator
NewBytesComparator creates a new BytesComparator.
func (*BytesComparator) CompareValues ¶ added in v1.6.0
func (vc *BytesComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*BytesComparator) Supports ¶ added in v1.6.0
func (vc *BytesComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type CanInterfaceComparator ¶ added in v1.6.0
type CanInterfaceComparator struct {
ValuesComparator
}
CanInterfaceComparator is a ValuesComparator that attempts to convert the [reflect.Value]s so they can be used with reflect.Value.Interface.
It should be created with NewCanInterfaceComparator.
func NewCanInterfaceComparator ¶ added in v1.6.0
func NewCanInterfaceComparator(vc ValuesComparator) *CanInterfaceComparator
NewCanInterfaceComparator creates a new CanInterfaceComparator.
func (*CanInterfaceComparator) CompareValues ¶ added in v1.6.0
func (vc *CanInterfaceComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type ChanComparator ¶ added in v1.6.0
type ChanComparator struct{}
ChanComparator is a ValuesComparator for chan values.
It should be created with NewChanComparator.
func NewChanComparator ¶ added in v1.6.0
func NewChanComparator() *ChanComparator
NewChanComparator creates a new ChanComparator.
func (*ChanComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*ChanComparator) Supports ¶ added in v1.6.0
func (vc *ChanComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type CommonComparator ¶ added in v1.6.0
type CommonComparator struct {
Recursion *RecursionComparator
MaxDepth *MaxDepthComparator
CanInterface *CanInterfaceComparator
ByType ByTypeComparators
ValuesComparators ValuesComparators
Support *SupportComparator
ReflectValue *ReflectValueComparator
Bytes *BytesComparator
Equal *FilterComparator[*EqualComparator]
Compare *FilterComparator[*CompareComparator]
Kind *KindComparator
}
CommonComparator is a ValuesComparator with common [ValuesComparator]s.
Any ValuesComparator can be configured, and can be set to nil in order to disable it.
It should be created with NewCommonComparator.
func NewCommonComparator ¶ added in v1.6.0
func NewCommonComparator() *CommonComparator
NewCommonComparator creates a new CommonComparator initialized with default values.
func (*CommonComparator) CompareValues ¶ added in v1.6.0
func (vc *CommonComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*CommonComparator) Supports ¶ added in v1.6.0
func (vc *CommonComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type Comparator ¶ added in v1.3.0
type Comparator struct {
ValuesComparator ValuesComparator
}
Comparator is a value comparator.
It should be created with NewComparator.
func NewComparator ¶ added in v1.3.0
func NewComparator(vc ValuesComparator) *Comparator
NewComparator creates a new Comparator.
func (*Comparator) Compare ¶ added in v1.3.0
func (c *Comparator) Compare(iv1, iv2 any) Result
Compare compares 2 values.
type CompareComparator ¶ added in v1.6.0
type CompareComparator struct {
// CompareNames is the list of method names to look for, tried in order.
// Default: ["Compare", "Cmp"].
CompareNames []string
}
CompareComparator is a ValuesComparator that compares values with a method that returns a comparison result (for example Compare(T) int).
It should be created with NewCompareComparator.
func NewCompareComparator ¶ added in v1.6.0
func NewCompareComparator() *CompareComparator
NewCompareComparator creates a new CompareComparator.
func (*CompareComparator) CompareValues ¶ added in v1.6.0
func (vc *CompareComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*CompareComparator) Supports ¶ added in v1.6.0
func (vc *CompareComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type ComplexComparator ¶ added in v1.6.0
type ComplexComparator struct {
// NaNEqual controls whether the real and imaginary parts with NaN values compare equal.
// Default: true
NaNEqual bool
// SignedZeroEqual controls whether real and imaginary parts with +0.0 and -0.0 compare equal.
// Default: true
SignedZeroEqual bool
}
ComplexComparator is a ValuesComparator for complex values.
It should be created with NewComplexComparator.
func NewComplexComparator ¶ added in v1.6.0
func NewComplexComparator() *ComplexComparator
NewComplexComparator creates a new ComplexComparator.
func (*ComplexComparator) CompareValues ¶ added in v1.6.0
func (vc *ComplexComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*ComplexComparator) Supports ¶ added in v1.6.0
func (vc *ComplexComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type Difference ¶
Difference represents a difference between 2 values.
func (Difference) AppendText ¶ added in v1.6.0
func (d Difference) AppendText(b []byte) ([]byte, error)
AppendText implements encoding.TextAppender.
func (Difference) AppendTo ¶ added in v1.6.0
func (d Difference) AppendTo(b []byte) []byte
AppendTo appends the text representation to a []byte.
func (Difference) String ¶ added in v1.6.0
func (d Difference) String() string
type EqualComparator ¶ added in v1.6.0
type EqualComparator struct {
// Names is the list of method names to look for, tried in order.
// Default: ["Equal", "Eq"].
Names []string
}
EqualComparator is a ValuesComparator that compares values with a method that reports equality (for example Equal(T) bool).
It should be created with NewEqualComparator.
func NewEqualComparator ¶ added in v1.6.0
func NewEqualComparator() *EqualComparator
NewEqualComparator creates a new EqualComparator.
func (*EqualComparator) CompareValues ¶ added in v1.6.0
func (vc *EqualComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*EqualComparator) Supports ¶ added in v1.6.0
func (vc *EqualComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type FilterComparator ¶ added in v1.6.0
type FilterComparator[VC ValuesComparator] struct { ValuesComparator VC // Filter filters types. // The value is handled if it returns true or if it is nil. Filter func(typ reflect.Type) bool }
FilterComparator is a ValuesComparator that calls the ValuesComparator if the filter returns true.
It should be created with NewFilterComparator.
func NewFilterComparator ¶ added in v1.6.0
func NewFilterComparator[VC ValuesComparator](vc VC, f func(typ reflect.Type) bool) *FilterComparator[VC]
NewFilterComparator creates a new FilterComparator.
func (*FilterComparator[VC]) CompareValues ¶ added in v1.6.0
func (vc *FilterComparator[VC]) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*FilterComparator[VC]) Supports ¶ added in v1.6.0
func (vc *FilterComparator[VC]) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type FloatComparator ¶ added in v1.6.0
type FloatComparator struct {
// NaNEqual controls whether two NaN values compare equal.
// Default: true.
NaNEqual bool
// SignedZeroEqual controls whether +0.0 and -0.0 compare equal.
// Default: true.
SignedZeroEqual bool
}
FloatComparator is a ValuesComparator for float values.
It should be created with NewFloatComparator.
func NewFloatComparator ¶ added in v1.6.0
func NewFloatComparator() *FloatComparator
NewFloatComparator creates a new FloatComparator.
func (*FloatComparator) CompareValues ¶ added in v1.6.0
func (vc *FloatComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*FloatComparator) Supports ¶ added in v1.6.0
func (vc *FloatComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type FuncComparator ¶ added in v1.6.0
type FuncComparator struct{}
FuncComparator is a ValuesComparator for func values.
It should be created with NewFuncComparator.
func NewFuncComparator ¶ added in v1.6.0
func NewFuncComparator() *FuncComparator
NewFuncComparator creates a new FuncComparator.
func (*FuncComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*FuncComparator) Supports ¶ added in v1.6.0
func (vc *FuncComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type IntComparator ¶ added in v1.6.0
type IntComparator struct{}
IntComparator is a ValuesComparator for int values.
It should be created with NewIntComparator.
func NewIntComparator ¶ added in v1.6.0
func NewIntComparator() *IntComparator
NewIntComparator creates a new IntComparator.
func (*IntComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*IntComparator) Supports ¶ added in v1.6.0
func (vc *IntComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type InterfaceComparator ¶ added in v1.6.0
type InterfaceComparator struct {
ValuesComparator
}
InterfaceComparator is a ValuesComparator for interface values.
It should be created with NewInterfaceComparator.
func NewInterfaceComparator ¶ added in v1.6.0
func NewInterfaceComparator(vc ValuesComparator) *InterfaceComparator
NewInterfaceComparator creates a new InterfaceComparator.
func (*InterfaceComparator) CompareValues ¶ added in v1.6.0
func (vc *InterfaceComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*InterfaceComparator) Supports ¶ added in v1.6.0
func (vc *InterfaceComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type KindComparator ¶ added in v1.6.0
type KindComparator struct {
Bool *BoolComparator
Int *IntComparator
Uint *UintComparator
Float *FloatComparator
Complex *ComplexComparator
Array *ArrayComparator
Chan *ChanComparator
Func *FuncComparator
Interface *InterfaceComparator
Map *MapComparator
Pointer *PointerComparator
Slice *SliceComparator
String *StringComparator
Struct *StructComparator
UnsafePointer *UnsafePointerComparator
ValuesComparators [kindsCount]ValuesComparator
}
KindComparator is a ValuesComparator for different kinds of values.
It should be created with NewKindComparator.
func NewKindComparator ¶ added in v1.6.0
func NewKindComparator(vc ValuesComparator) *KindComparator
NewKindComparator creates a new KindComparator.
func (*KindComparator) CompareValues ¶ added in v1.6.0
func (kvc *KindComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*KindComparator) Supports ¶ added in v1.6.0
func (kvc *KindComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type MapComparator ¶ added in v1.6.0
type MapComparator struct {
ValuesComparator
// MaxDifferences is the maximum number of different items to report.
// If reached, the comparison is stopped for the current map.
// Setting it to 0 disables it.
// Default: 10.
MaxDifferences int
}
MapComparator is a ValuesComparator for map values.
It should be created with NewMapComparator.
func NewMapComparator ¶ added in v1.6.0
func NewMapComparator(vc ValuesComparator) *MapComparator
NewMapComparator creates a new MapComparator.
func (*MapComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*MapComparator) Supports ¶ added in v1.6.0
func (vc *MapComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type MaxDepthComparator ¶ added in v1.6.0
type MaxDepthComparator struct {
ValuesComparator
// Max is the maximum depth.
// Default: 0 (no limit).
Max int
// Report controls whether a difference is reported if the max depth is reached.
// Default: true.
Report bool
}
MaxDepthComparator is a ValuesComparator that limits the comparison depth.
It should be created with NewMaxDepthComparator.
func NewMaxDepthComparator ¶ added in v1.6.0
func NewMaxDepthComparator(vc ValuesComparator) *MaxDepthComparator
NewMaxDepthComparator creates a new MaxDepthComparator.
func (*MaxDepthComparator) CompareValues ¶ added in v1.6.0
func (vc *MaxDepthComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type Path ¶
type Path []PathElem
Path represents a path in a data structure.
Elements are stored in reverse order; the first element is the deepest. It helps to prepend elements to the path efficiently.
func (Path) AppendText ¶ added in v1.6.0
AppendText implements encoding.TextAppender.
type PathElem ¶ added in v1.2.0
PathElem represents an element in a Path.
func (PathElem) AppendText ¶ added in v1.6.0
AppendText implements encoding.TextAppender.
type PointerComparator ¶ added in v1.6.0
type PointerComparator struct {
ValuesComparator
}
PointerComparator is a ValuesComparator for pointer values.
It should be created with NewPointerComparator.
func NewPointerComparator ¶ added in v1.6.0
func NewPointerComparator(vc ValuesComparator) *PointerComparator
NewPointerComparator creates a new PointerComparator.
func (*PointerComparator) CompareValues ¶ added in v1.6.0
func (vc *PointerComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*PointerComparator) Supports ¶ added in v1.6.0
func (vc *PointerComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type RecursionComparator ¶ added in v1.6.0
type RecursionComparator struct {
ValuesComparator
}
RecursionComparator is a ValuesComparator that prevents infinite recursion.
It should be created with NewRecursionComparator.
func NewRecursionComparator ¶ added in v1.6.0
func NewRecursionComparator(vc ValuesComparator) *RecursionComparator
NewRecursionComparator creates a new RecursionComparator.
func (*RecursionComparator) CompareValues ¶ added in v1.6.0
func (vc *RecursionComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type ReflectValueComparator ¶ added in v1.6.0
type ReflectValueComparator struct {
ValuesComparator
}
ReflectValueComparator is a ValuesComparator for reflect.Value values.
It unwraps the values and compares the wrapped values.
It should be created with NewReflectValueComparator.
func NewReflectValueComparator ¶ added in v1.6.0
func NewReflectValueComparator(vc ValuesComparator) *ReflectValueComparator
NewReflectValueComparator creates a new ReflectValueComparator.
func (*ReflectValueComparator) CompareValues ¶ added in v1.6.0
func (vc *ReflectValueComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*ReflectValueComparator) Supports ¶ added in v1.6.0
func (vc *ReflectValueComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type Result ¶
type Result []Difference
Result represents the result of the comparison of 2 values. It's a list of Difference.
func Res ¶ added in v1.6.0
Res creates a new Result with a single Difference.
func (Result) AppendPathElem ¶ added in v1.6.0
AppendPathElem appends a PathElem to the Path of all [Difference]s of the Result.
func (Result) AppendText ¶ added in v1.6.0
AppendText implements encoding.TextAppender.
type SliceComparator ¶ added in v1.6.0
type SliceComparator struct {
ValuesComparator
// MaxDifferences is the maximum number of different items to report.
// If reached, the comparison is stopped for the current slice.
// Setting it to 0 disables it.
// Default: 10.
MaxDifferences int
}
SliceComparator is a ValuesComparator for slice values.
It should be created with NewSliceComparator.
func NewSliceComparator ¶ added in v1.6.0
func NewSliceComparator(vc ValuesComparator) *SliceComparator
NewSliceComparator creates a new SliceComparator.
func (*SliceComparator) CompareValues ¶ added in v1.6.0
func (vc *SliceComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*SliceComparator) Supports ¶ added in v1.6.0
func (vc *SliceComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type State ¶ added in v1.4.0
type State struct {
// Depth is the current comparison depth.
Depth int
// Visited contains the visited value pairs, to prevent recursion.
Visited map[VisitedEntry]struct{}
}
State represents the state of a running comparison.
Functions must restore the original state when they return.
type StringComparator ¶ added in v1.6.0
type StringComparator struct{}
StringComparator is a ValuesComparator for string values.
It should be created with NewStringComparator.
func NewStringComparator ¶ added in v1.6.0
func NewStringComparator() *StringComparator
NewStringComparator creates a new StringComparator.
func (*StringComparator) CompareValues ¶ added in v1.6.0
func (vc *StringComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*StringComparator) Supports ¶ added in v1.6.0
func (vc *StringComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type StructComparator ¶ added in v1.6.0
type StructComparator struct {
ValuesComparator
}
StructComparator is a ValuesComparator for struct values.
It should be created with NewStructComparator.
func NewStructComparator ¶ added in v1.6.0
func NewStructComparator(vc ValuesComparator) *StructComparator
NewStructComparator creates a new StructComparator.
func (*StructComparator) CompareValues ¶ added in v1.6.0
func (vc *StructComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*StructComparator) Supports ¶ added in v1.6.0
func (vc *StructComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type SupportChecker ¶ added in v1.6.0
type SupportChecker interface {
Supports(typ reflect.Type) ValuesComparator
}
SupportChecker checks if a reflect.Type is supported. If the reflect.Type is supported, it returns a non-nil ValuesComparator.
type SupportCheckerFunc ¶ added in v1.6.0
type SupportCheckerFunc func(typ reflect.Type) ValuesComparator
SupportCheckerFunc is a SupportChecker function.
func (SupportCheckerFunc) Supports ¶ added in v1.6.0
func (f SupportCheckerFunc) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type SupportCheckerValuesComparator ¶ added in v1.6.0
type SupportCheckerValuesComparator struct {
ValuesComparator
SupportChecker
}
SupportCheckerValuesComparator implements ValuesComparator and SupportChecker.
type SupportComparator ¶ added in v1.6.0
type SupportComparator struct {
Checkers []SupportChecker
// contains filtered or unexported fields
}
SupportComparator is a ValuesComparator that selects a ValuesComparator based on the reflect.Type of the values. It selects the first SupportChecker that supports the reflect.Type.
It should be created with NewSupportComparator.
func NewSupportComparator ¶ added in v1.6.0
func NewSupportComparator() *SupportComparator
NewSupportComparator creates a new SupportComparator.
func (*SupportComparator) CompareValues ¶ added in v1.6.0
func (vc *SupportComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type UintComparator ¶ added in v1.6.0
type UintComparator struct{}
UintComparator is a ValuesComparator for uint values.
It should be created with NewUintComparator.
func NewUintComparator ¶ added in v1.6.0
func NewUintComparator() *UintComparator
NewUintComparator creates a new UintComparator.
func (*UintComparator) CompareValues ¶ added in v1.6.0
CompareValues implements ValuesComparator.
func (*UintComparator) Supports ¶ added in v1.6.0
func (vc *UintComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type UnsafePointerComparator ¶ added in v1.6.0
type UnsafePointerComparator struct{}
UnsafePointerComparator is a ValuesComparator for unsafe.Pointer values.
It should be created with NewUnsafePointerComparator.
func NewUnsafePointerComparator ¶ added in v1.6.0
func NewUnsafePointerComparator() *UnsafePointerComparator
NewUnsafePointerComparator creates a new UnsafePointerComparator.
func (*UnsafePointerComparator) CompareValues ¶ added in v1.6.0
func (vc *UnsafePointerComparator) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
func (*UnsafePointerComparator) Supports ¶ added in v1.6.0
func (vc *UnsafePointerComparator) Supports(typ reflect.Type) ValuesComparator
Supports implements SupportChecker.
type ValuesComparator ¶ added in v1.6.0
type ValuesComparator interface {
CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
}
ValuesComparator compares 2 values. The returned handled value is true if the comparator handled the value, and false otherwise.
Implementations can assume that both values are valid and have the same type.
type ValuesComparatorFunc ¶ added in v1.6.0
ValuesComparatorFunc is a ValuesComparator function.
func (ValuesComparatorFunc) CompareValues ¶ added in v1.6.0
func (f ValuesComparatorFunc) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
type ValuesComparators ¶ added in v1.6.0
type ValuesComparators []ValuesComparator
ValuesComparators is a list of [ValuesComparator]s.
They are tried in order until one handles the value.
func (ValuesComparators) CompareValues ¶ added in v1.6.0
func (vcs ValuesComparators) CompareValues(st *State, v1, v2 reflect.Value) (res Result, handled bool)
CompareValues implements ValuesComparator.
Source Files
¶
- array.go
- bool.go
- bytes.go
- can_interface.go
- chan.go
- common.go
- comparator.go
- compare.go
- complex.go
- doc.go
- equal.go
- filter.go
- float.go
- func.go
- int.go
- interface.go
- kind.go
- map.go
- max_depth.go
- nil.go
- path.go
- pointer.go
- recursion.go
- reflect_value.go
- result.go
- slice.go
- state.go
- string.go
- struct.go
- support.go
- type.go
- uint.go
- unsafe_pointer.go
- util.go
- values_comparator.go
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
comparetest
Package comparetest provides utilities for testing the compare package.
|
Package comparetest provides utilities for testing the compare package. |