shakers – github.com/vdemeester/shakers Index | Files

package shakers

import "github.com/vdemeester/shakers"

Package shakers provide some checker implementation the go-check.Checker interface.

Index

Variables

var (
	DeepEquals   = check.DeepEquals
	ErrorMatches = check.ErrorMatches
	FitsTypeOf   = check.FitsTypeOf
	HasLen       = check.HasLen
	Implements   = check.Implements
	IsNil        = check.IsNil
	Matches      = check.Matches
	Not          = check.Not
	NotNil       = check.NotNil
	PanicMatches = check.PanicMatches
	Panics       = check.Panics
)

As a commodity, we bring all check.Checker variables into the current namespace to avoid having to think about check.X versus checker.X.

var Contains check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "Contains",
		Params: []string{"obtained", "substring"},
	},
	strings.Contains,
}

Contains checker verifies that obtained value contains a substring.

var ContainsAny check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "ContainsAny",
		Params: []string{"obtained", "chars"},
	},
	strings.ContainsAny,
}

ContainsAny checker verifies that any Unicode code points in chars are in the obtained string.

var Count check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "Count",
		Params: []string{"obtained", "sep", "expected"},
	},
	strings.Count,
}

Count checker verifies that obtained value has the specified number of non-overlapping instances of sep

var EqualFold check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "EqualFold",
		Params: []string{"obtained", "expected"},
	},
	strings.EqualFold,
}

EqualFold checker verifies that obtained value is, interpreted as UTF-8 strings, are equal under Unicode case-folding.

var Equals check.Checker = &equalChecker{
	&check.CheckerInfo{
		Name:   "Equals",
		Params: []string{"obtained", "expected"},
	},
}

Equals checker verifies the obtained value is equal to the specified one. It's is smart in a wait that it supports several *types* (built-in, Equaler, time.Time)

c.Assert(myStruct, Equals, aStruct, check.Commentf("bouuuhh"))
c.Assert(myTime, Equals, aTime, check.Commentf("bouuuhh"))
var False check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "False",
		Params: []string{"obtained"},
	},
	false,
}

False checker verifies the obtained value is false

c.Assert(myBool, False)
var GreaterOrEqualThan check.Checker = &greaterOrEqualThanChecker{
	&check.CheckerInfo{
		Name:   "GreaterOrEqualThan",
		Params: []string{"obtained", "expected"},
	},
}

GreaterOrEqualThan checker verifies the obtained value is greater or equal than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, GreaterOrEqualThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, GreaterOrEqualThan, 2, check.Commentf("bouuuhh"))
var GreaterThan check.Checker = &greaterThanChecker{
	&check.CheckerInfo{
		Name:   "GreaterThan",
		Params: []string{"obtained", "expected"},
	},
}

GreaterThan checker verifies the obtained value is greater than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, GreaterThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, GreaterThan, 2, check.Commentf("bouuuhh"))
var HasPrefix check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "HasPrefix",
		Params: []string{"obtained", "prefix"},
	},
	strings.HasPrefix,
}

HasPrefix checker verifies that obtained value has the specified substring as prefix

var HasSuffix check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "HasSuffix",
		Params: []string{"obtained", "suffix"},
	},
	strings.HasSuffix,
}

HasSuffix checker verifies that obtained value has the specified substring as prefix

var Index check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "Index",
		Params: []string{"obtained", "sep", "expected"},
	},
	strings.Index,
}

Index checker verifies that the index of the first instance of sep in the obtained value is equal to expected

var IndexAny check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "IndexAny",
		Params: []string{"obtained", "chars", "expected"},
	},
	strings.IndexAny,
}

IndexAny checker verifies that the index of the first instance of any Unicode code point from chars in the obtained value is equal to expected

var IsAfter check.Checker = &isAfterChecker{
	&check.CheckerInfo{
		Name:   "IsAfter",
		Params: []string{"obtained", "expected"},
	},
}

IsAfter checker verifies the specified value is before the specified time. It is exclusive.

c.Assert(myTime, IsAfter, theTime, check.Commentf("bouuuhhh"))
var IsBefore check.Checker = &isBeforeChecker{
	&check.CheckerInfo{
		Name:   "IsBefore",
		Params: []string{"obtained", "expected"},
	},
}

IsBefore checker verifies the specified value is before the specified time. It is exclusive.

c.Assert(myTime, IsBefore, theTime, check.Commentf("bouuuhhh"))
var IsBetween check.Checker = &isBetweenChecker{
	&check.CheckerInfo{
		Name:   "IsBetween",
		Params: []string{"obtained", "start", "end"},
	},
}

IsBetween checker verifies the specified time is between the specified start and end. It's exclusive so if the specified time is at the tip of the interval.

c.Assert(myTime, IsBetween, startTime, endTime, check.Commentf("bouuuhhh"))
var IsLower check.Checker = &stringTransformChecker{
	&check.CheckerInfo{
		Name:   "IsLower",
		Params: []string{"obtained"},
	},
	strings.ToLower,
}

IsLower checker verifies that the obtained value is in lower case

var IsUpper check.Checker = &stringTransformChecker{
	&check.CheckerInfo{
		Name:   "IsUpper",
		Params: []string{"obtained"},
	},
	strings.ToUpper,
}

IsUpper checker verifies that the obtained value is in lower case

var LessOrEqualThan check.Checker = &lessOrEqualThanChecker{
	&check.CheckerInfo{
		Name:   "LessOrEqualThan",
		Params: []string{"obtained", "expected"},
	},
}

LessOrEqualThan checker verifies the obtained value is less or equal than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, LessThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, LessThan, 2, check.Commentf("bouuuhh"))
var LessThan check.Checker = &lessThanChecker{
	&check.CheckerInfo{
		Name:   "LessThan",
		Params: []string{"obtained", "expected"},
	},
}

LessThan checker verifies the obtained value is less than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, LessThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, LessThan, 2, check.Commentf("bouuuhh"))
var TimeEquals check.Checker = &timeEqualsChecker{
	&check.CheckerInfo{
		Name:   "TimeEquals",
		Params: []string{"obtained", "expected"},
	},
}

TimeEquals checker verifies the specified time is the equal to the expected time.

c.Assert(myTime, TimeEquals, expected, check.Commentf("bouhhh"))

It's possible to ignore some part of the time (like hours, minutes, etc..) using the TimeIgnore checker with it.

c.Assert(myTime, TimeIgnore(TimeEquals, time.Hour), expected, check.Commentf("... bouh.."))
var True check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "True",
		Params: []string{"obtained"},
	},
	true,
}

True checker verifies the obtained value is true

c.Assert(myBool, True)

Functions

func TimeIgnore

func TimeIgnore(checker check.Checker, ignore time.Duration) check.Checker

TimeIgnore checker will ignore some part of the time on the encapsulated checker.

c.Assert(myTime, TimeIgnore(IsBetween, time.Second), start, end)

FIXME use interface{} for ignore (to enable "Month", ..

Types

type Equaler

type Equaler interface {
	Equal(Equaler) bool
}

Equaler is an interface implemented if the type has a Equal method. This is used to compare struct using shakers.Equals.

Source Files

bool.go common.go string.go time.go

Version
v0.1.0 (latest)
Published
Feb 10, 2016
Platform
linux/amd64
Imports
5 packages
Last checked
now

Tools for package owners.