deep

package module
v0.0.0-...-a37cba0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 5 Imported by: 0

README

GoDoc

Deep

The deep package provides deep comparisons with human-readable differences and configurable tolerances. Useful for testing.

This project derives from several others:

Documentation

Overview

The deep package provides deep comparisons with options.

Index

Constants

This section is empty.

Variables

View Source
var Config = NewComparer()

Config is the Comparer used by Equal.

Functions

This section is empty.

Types

type Comparer

type Comparer struct {
	// CompareUnexportedFields, when true, causes unexported fields to be
	// compared.
	CompareUnexportedFields bool
	// FloatPrecision sets the amount of mantissa precision, in bits, used when
	// comparing floats. A value of zero or less uses an exact equality
	// comparison.
	FloatPrecision int
	// MaxDepth specifies the maximum depth below which values will be
	// automatically be considered equal. A value of zero or less indicates an
	// infinite maxmimum depth.
	MaxDepth int
	// MaxDiffs specifies the maximum number of diffs to be returned. A value of
	// zero or less indicates an infinite maximum amount.
	MaxDiffs int
	// NilMapsAreEmpty, when true, causes nil maps to be equal to maps with zero
	// elements.
	NilMapsAreEmpty bool
	// NilSlicesAreEmpty, when true, causes nil slices to be equal to slices
	// with zero elements.
	NilSlicesAreEmpty bool
}

Comparer configures how comparisons are made.

func NewComparer

func NewComparer() *Comparer

NewComparer returns a new Comparer with a sensible default configuration.

For the purposes of testing, NewComparer should be avoided. A Comparer with the desired options should be created manually.

func (Comparer) Equal

func (c Comparer) Equal(x, y interface{}) []Diff

Equal makes a comparison between two values, and returns a list of differences between them. If the values are equivalent according to the current configuration, then nil is returned.

Equal makes comparisons based on equivalency rather than equality. Values may or may not be equivalent depending on the tolerances configured by the Comparer. Generally, Equal is similar to reflect.Equal. Aside from the configurable options, there are several other differences:

  • NaN is equivalent to NaN.
  • Because of quirks with maps, maps containing NaN keys can be reported incorrectly.

type Diff

type Diff struct {
	// contains filtered or unexported fields
}

Diff represents a single unit of difference between two values.

func Equal

func Equal(x, y interface{}) []Diff

Equal makes a comparison between two values, and returns a list of differences between them. If the values are equivalent according to the global configuration, then nil is returned.

func (Diff) String

func (d Diff) String() string

String returns a string representation of the diff. The returned string is meant to be read by humans, so it is not guaranteed to be consistent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL