testconv

package
v0.0.0-...-66a2b2b Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeKind reflect.Kind = reflect.UnsafePointer + iota
	DurationKind
	TimeKind
	SliceMask reflect.Kind = (1 << 8)
	MapMask                = (1 << 16)
	ChanMask               = (1 << 24)
)
View Source
const (
	IntSize int  = 32 << (^uint(0) >> 63)
	MinUint uint = 0
	MaxUint uint = ^MinUint
	MaxInt  int  = int(MaxUint >> 1)
	MinInt  int  = ^MaxInt
)

Numeric constants for testing.

Variables

This section is empty.

Functions

func RunBoolTests

func RunBoolTests(t *testing.T, fn func(interface{}) (bool, error))

func RunDurationTests

func RunDurationTests(t *testing.T, fn func(interface{}) (time.Duration, error))

func RunFloat32Tests

func RunFloat32Tests(t *testing.T, fn func(interface{}) (float32, error))

func RunFloat64Tests

func RunFloat64Tests(t *testing.T, fn func(interface{}) (float64, error))

func RunInferTests

func RunInferTests(t *testing.T, fn func(into, from interface{}) error)

func RunInt16Tests

func RunInt16Tests(t *testing.T, fn func(interface{}) (int16, error))

func RunInt32Tests

func RunInt32Tests(t *testing.T, fn func(interface{}) (int32, error))

func RunInt64Tests

func RunInt64Tests(t *testing.T, fn func(interface{}) (int64, error))

func RunInt8Tests

func RunInt8Tests(t *testing.T, fn func(interface{}) (int8, error))

func RunIntTests

func RunIntTests(t *testing.T, fn func(interface{}) (int, error))

func RunReadmeTest

func RunReadmeTest(t *testing.T, srcs ...string)

func RunStringTests

func RunStringTests(t *testing.T, fn func(interface{}) (string, error))

func RunTest

func RunTest(t *testing.T, k reflect.Kind, fn func(interface{}) (interface{}, error))

func RunTimeTests

func RunTimeTests(t *testing.T, fn func(interface{}) (time.Time, error))

func RunUint16Tests

func RunUint16Tests(t *testing.T, fn func(interface{}) (uint16, error))

func RunUint32Tests

func RunUint32Tests(t *testing.T, fn func(interface{}) (uint32, error))

func RunUint64Tests

func RunUint64Tests(t *testing.T, fn func(interface{}) (uint64, error))

func RunUint8Tests

func RunUint8Tests(t *testing.T, fn func(interface{}) (uint8, error))

func RunUintTests

func RunUintTests(t *testing.T, fn func(interface{}) (uint, error))

Types

type Assertion

type Assertion struct {

	// From is the underlying value to be used in conversions.
	From interface{}

	// Name of this assertion
	Name string

	// Code to construct Interface
	Code string

	// Type of Interface field using fmt %#T.
	Type string

	// File is the file the assertion is defined in.
	File string

	// Line is the line number the assertion is defined in.
	Line int

	// Description for this assertion.
	Desc string

	// Expects contains a list of values this Assertion expects to see as a result
	// of calling the conversion function for the associated type. For example
	// appending a single int64 to this slice would mean it is expected that:
	//   conv.Int64(assertion.From) == Expect[0].(int64)
	// When appending multiple values of the same type, the last one appended is
	// used.
	Exps []Expecter
}

Assertion represents a set of expected values from a Converter. It's the general implementation of asserter. It will compare each Expects to the associated Converter.T(). It returns an error for each failed conversion or an empty error slice if no failures occurred.

func (Assertion) String

func (a Assertion) String() string

type Assertions

type Assertions []*Assertion

Assertions is slice of assertions.

func (Assertions) EachOf

func (a Assertions) EachOf(k reflect.Kind, f func(a *Assertion, e Expecter)) int

EachOf will visit each assertion that contains an Expecter for reflect.Kind.

type AssertionsIndex

type AssertionsIndex map[reflect.Kind][]AssertionsLookup

AssertionsIndex is map of assertions by the Expecter kind.

type AssertionsLookup

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

type DurationExp

type DurationExp struct {
	Want  time.Duration
	Round time.Duration
}

DurationExp supports fuzzy duration conversions.

func (DurationExp) Expect

func (e DurationExp) Expect(got interface{}, err error) error

func (DurationExp) Kind

func (e DurationExp) Kind() reflect.Kind

func (DurationExp) Value

func (e DurationExp) Value() interface{}

type ErrorExp

type ErrorExp struct {
	Exp
	ErrStr string
}

ErrorExp ensures a given conversion failed.

func (ErrorExp) Expect

func (e ErrorExp) Expect(got interface{}, err error) error

type Exp

type Exp struct {
	Want interface{}
}

Exp is used for ducmentation purposes.

func (Exp) Expect

func (e Exp) Expect(got interface{}, err error) error

func (Exp) Kind

func (e Exp) Kind() reflect.Kind

func (Exp) String

func (e Exp) String() string

func (Exp) Value

func (e Exp) Value() interface{}

type Expecter

type Expecter interface {

	// Exp is given the result of conversion and an error if one occurred. The
	// type of conversion operation should be the type of Kind().
	Expect(got interface{}, err error) error

	// Value is the expected result.
	Value() interface{}

	// Kind returns the type of conversion that should be given to Exepct().
	Kind() reflect.Kind
}

Expecter defines a type of conversion for v and will return an error if the value is unexpected.

type Float32Exp

type Float32Exp struct {
	Want float32
}

Float32Exp asserts that (converter.Float32() - Exp) < epsilon64

func (Float32Exp) Expect

func (e Float32Exp) Expect(got interface{}, err error) error

func (Float32Exp) Kind

func (e Float32Exp) Kind() reflect.Kind

func (Float32Exp) Value

func (e Float32Exp) Value() interface{}

type Float64Exp

type Float64Exp struct {
	Want float64
}

Float64Exp asserts that (converter.Float64() - Exp) < epsilon64

func (Float64Exp) Expect

func (e Float64Exp) Expect(got interface{}, err error) error

func (Float64Exp) Kind

func (e Float64Exp) Kind() reflect.Kind

func (Float64Exp) Value

func (e Float64Exp) Value() interface{}

type ReadmeExample

type ReadmeExample struct {
	Example  *doc.Example
	Complete bool
	Title    string
	Summary  string
	Code     string
	Output   string
}

type ReadmeExamples

type ReadmeExamples []ReadmeExample

func (ReadmeExamples) Len

func (r ReadmeExamples) Len() int

func (ReadmeExamples) Less

func (r ReadmeExamples) Less(i, j int) bool

func (ReadmeExamples) Swap

func (r ReadmeExamples) Swap(i, j int)

type SrcGen

type SrcGen struct {
	Disabled    bool
	Data        interface{}
	FuncMap     template.FuncMap
	Name        string
	SrcPath     string
	SrcBytes    []byte
	TplPath     string
	TplBytes    []byte // Actual template bytes
	TplGenBytes []byte // Bytes produced from executed template
	// contains filtered or unexported fields
}

func NewSrcGen

func NewSrcGen(name string) *SrcGen

func (*SrcGen) Check

func (g *SrcGen) Check() error

func (*SrcGen) Commit

func (g *SrcGen) Commit() error

func (*SrcGen) Dump

func (g *SrcGen) Dump(w io.Writer) string

func (*SrcGen) Format

func (g *SrcGen) Format() error

func (*SrcGen) Generate

func (g *SrcGen) Generate() error

func (*SrcGen) IsStale

func (g *SrcGen) IsStale() bool

func (*SrcGen) Load

func (g *SrcGen) Load() error

func (*SrcGen) Run

func (g *SrcGen) Run() error

func (*SrcGen) String

func (g *SrcGen) String() string

type TimeExp

type TimeExp struct {
	Moment   time.Time
	Offset   time.Duration
	Round    time.Duration
	Truncate time.Duration
}

TimeExp helps validate time.Time() conversions, specifically because under some conversions time.Now() may be used. It will check that the difference between the Moment is the same as the given value after truncation and rounding (if either is set) is identical.

func (TimeExp) Expect

func (e TimeExp) Expect(got interface{}, err error) error

func (TimeExp) Kind

func (e TimeExp) Kind() reflect.Kind

func (TimeExp) String

func (e TimeExp) String() string

func (TimeExp) Value

func (e TimeExp) Value() interface{}

Jump to

Keyboard shortcuts

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