Documentation ¶
Index ¶
- Constants
- func CompareObjects(v1, v2 any, opts *ObjectOpts) string
- func CompareStrings(s1, s2 string, opts *StringOpts) (s string)
- func Equivalent(v1, v2 any) (same bool)
- func ReflectorsToNameString[S ~[]E, E any](in S) (names string)
- func SliceReduceFunc[S ~[]E, E any, R any](s S, f func(any, R) R) (r R)
- func SortReflectValues(rvs []reflect.Value) []reflect.Value
- func SortedMapKeys(a any) (keys []reflect.Value)
- type BoolValue
- type Comparator
- type Diffator
- type IntValue
- type ObjectComparator
- type ObjectOpts
- type Reflector
- func (r *Reflector) Any() any
- func (r *Reflector) AsAny(rv *reflect.Value) (a any)
- func (r *Reflector) AsString(rv *reflect.Value) (s string)
- func (r *Reflector) Child() *reflect.Value
- func (r *Reflector) ChildOf(rv *reflect.Value) (c *reflect.Value)
- func (r *Reflector) String() (s string)
- func (r *Reflector) Typename() string
- func (r *Reflector) TypenameOf(rv *reflect.Value) (n string)
- type StringComparator
- type StringOpts
- type StringValue
- type Tracker
- func (vId *Tracker) Delete(id ValueId)
- func (vId *Tracker) HaveSeen(rv *reflect.Value) (seen bool, id ValueId)
- func (vId *Tracker) HaveSeenId(id ValueId) (seen bool)
- func (vId *Tracker) Pop(id ValueId)
- func (vId *Tracker) Push(rv *reflect.Value) (seen bool, id ValueId)
- func (vId *Tracker) Seen() (seen ValueIdMap)
- func (vId *Tracker) SetSeen(seen ValueIdMap)
- type ValueId
- type ValueIdMap
Constants ¶
const LeftRightFormat = "<(%s/%s)>"
LeftRightFormat is default format used to format the differences found by `CompareStrings()` inline within the output string, would be the formatted when comparing these two (2) strings with the default format below:
Left String: "this shows left content inline" Right String: "this shows right content inline" Compare Output: "this shows (left/right) content inline"
const MinSubstrLen = 3
MinSubstrLen is the default length of a "common substring" as defined by being longer than 3 characters and not being a space.
Variables ¶
This section is empty.
Functions ¶
func CompareObjects ¶
func CompareObjects(v1, v2 any, opts *ObjectOpts) string
func CompareStrings ¶
func CompareStrings(s1, s2 string, opts *StringOpts) (s string)
func Equivalent ¶
func ReflectorsToNameString ¶
func SliceReduceFunc ¶
func SortedMapKeys ¶
Types ¶
type BoolValue ¶
type BoolValue struct {
Value bool
}
BoolValue enables a nil length, so we can set defaults on nil
type Comparator ¶
type Comparator interface {
Compare() string
}
type Diffator ¶
type Diffator struct {
Comparator
}
func NewDiffator ¶
func NewDiffator(c Comparator) *Diffator
type IntValue ¶
type IntValue struct {
Value int
}
IntValue enables a nil length, so we can set defaults on nil
type ObjectComparator ¶
type ObjectComparator struct {
// contains filtered or unexported fields
}
func NewObjectComparator ¶
func NewObjectComparator(v1, v2 any, opts *ObjectOpts) *ObjectComparator
func (*ObjectComparator) Compare ¶
func (o *ObjectComparator) Compare() string
func (*ObjectComparator) ReflectValuesDiff ¶
func (o *ObjectComparator) ReflectValuesDiff(rv1, rv2 *reflect.Value, format string) (diff string)
type ObjectOpts ¶
type ObjectOpts struct { LevelIndent *StringValue OutputFormat *StringValue PrettyPrint *BoolValue CompareFuncs bool FormatFunc func(reflect.Type, any) string }
func (*ObjectOpts) SetDefaults ¶
func (opts *ObjectOpts) SetDefaults()
type StringComparator ¶
type StringComparator struct {
// contains filtered or unexported fields
}
func NewStringComparator ¶
func NewStringComparator(s1, s2 string, opts *StringOpts) *StringComparator
func (*StringComparator) Compare ¶
func (c *StringComparator) Compare() (s string)
func (*StringComparator) Opts ¶
func (c *StringComparator) Opts() *StringOpts
type StringOpts ¶
type StringOpts struct { MatchingPadLen *IntValue MinSubstrLen *IntValue LeftRightFormat *StringValue }
func (*StringOpts) SetDefaults ¶
func (opts *StringOpts) SetDefaults()
type StringValue ¶
type StringValue struct {
Value string
}
StringValue enables a nil length so we can set defaults on nil
func String ¶
func String(s string) *StringValue
type Tracker ¶
func NewTracker ¶
func NewTracker() *Tracker
func NewTrackerWithKeys ¶
NewTrackerWithKeys returns sorted map keys as a slice, and a ValueIdTracker for the Value
func (*Tracker) HaveSeenId ¶
func (*Tracker) Seen ¶
func (vId *Tracker) Seen() (seen ValueIdMap)
func (*Tracker) SetSeen ¶
func (vId *Tracker) SetSeen(seen ValueIdMap)
type ValueId ¶
ValueId is used to compare the source value for original pointers
func NewValueId ¶
NewValueId returns a comparable struct for any reflect type.
type ValueIdMap ¶
type ValueIdMap map[ValueId]struct{}