Copyright 2017, The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE.md file.
Package cmpopts provides common options for the cmp package.
package cmpopts

import (
	
	
	

	
	
)

func (,  interface{}) bool { return true }
EquateEmpty returns a Comparer option that determines all maps and slices with a length of zero to be equal, regardless of whether they are nil. EquateEmpty can be used in conjunction with SortSlices and SortMaps.
func () cmp.Option {
	return cmp.FilterValues(isEmpty, cmp.Comparer(equateAlways))
}

func (,  interface{}) bool {
	,  := reflect.ValueOf(), reflect.ValueOf()
	return ( != nil &&  != nil && .Type() == .Type()) &&
		(.Kind() == reflect.Slice || .Kind() == reflect.Map) &&
		(.Len() == 0 && .Len() == 0)
}
EquateApprox returns a Comparer option that determines float32 or float64 values to be equal if they are within a relative fraction or absolute margin. This option is not used when either x or y is NaN or infinite. The fraction determines that the difference of two values must be within the smaller fraction of the two values, while the margin determines that the two values must be within some absolute margin. To express only a fraction or only a margin, use 0 for the other parameter. The fraction and margin must be non-negative. The mathematical expression used is equivalent to: |x-y| ≤ max(fraction*min(|x|, |y|), margin) EquateApprox can be used in conjunction with EquateNaNs.
func (,  float64) cmp.Option {
	if  < 0 ||  < 0 || math.IsNaN() || math.IsNaN() {
		panic("margin or fraction must be a non-negative number")
	}
	 := approximator{, }
	return cmp.Options{
		cmp.FilterValues(areRealF64s, cmp.Comparer(.compareF64)),
		cmp.FilterValues(areRealF32s, cmp.Comparer(.compareF32)),
	}
}

type approximator struct{ frac, marg float64 }

func (,  float64) bool {
	return !math.IsNaN() && !math.IsNaN() && !math.IsInf(, 0) && !math.IsInf(, 0)
}
func (,  float32) bool {
	return areRealF64s(float64(), float64())
}
func ( approximator) (,  float64) bool {
	 := .frac * math.Min(math.Abs(), math.Abs())
	return math.Abs(-) <= math.Max(.marg, )
}
func ( approximator) (,  float32) bool {
	return .compareF64(float64(), float64())
}
EquateNaNs returns a Comparer option that determines float32 and float64 NaN values to be equal. EquateNaNs can be used in conjunction with EquateApprox.
EquateApproxTime returns a Comparer option that determines two non-zero time.Time values to be equal if they are within some margin of one another. If both times have a monotonic clock reading, then the monotonic time difference will be used. The margin must be non-negative.
func ( time.Duration) cmp.Option {
	if  < 0 {
		panic("margin must be a non-negative number")
	}
	 := timeApproximator{}
	return cmp.FilterValues(areNonZeroTimes, cmp.Comparer(.compare))
}

func (,  time.Time) bool {
	return !.IsZero() && !.IsZero()
}

type timeApproximator struct {
	margin time.Duration
}

Avoid subtracting times to avoid overflow when the difference is larger than the largest representible duration.
Ensure x is always before y
		,  = , 
We're within the margin if x+margin >= y. Note: time.Time doesn't have AfterOrEqual method hence the negation.
	return !.Add(.margin).Before()
}
AnyError is an error that matches any non-nil error.
var AnyError anyError

type anyError struct{}

func (anyError) () string     { return "any error" }
func (anyError) ( error) bool { return  != nil }
EquateErrors returns a Comparer option that determines errors to be equal if errors.Is reports them to match. The AnyError error can be used to match any non-nil error.
areConcreteErrors reports whether x and y are types that implement error. The input types are deliberately of the interface{} type rather than the error type so that we can handle situations where the current type is an interface{}, but the underlying concrete types both happen to implement the error interface.
func (,  interface{}) bool {
	,  := .(error)
	,  := .(error)
	return  && 
}

func (,  interface{}) bool {
	 := .(error)
TODO(≥go1.13): Use standard definition of errors.Is.
	return xerrors.Is(, ) || xerrors.Is(, )