has

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllKeys

func AllKeys(expected ...interface{}) *gocrest.Matcher

AllKeys is a matcher that checks if map actual has all keys == expecteds. Panics when actual's Kind is not a map. Returns a matcher that matches when a map has all keys == all expected.

func EveryElement added in v1.0.5

func EveryElement(expects ...*gocrest.Matcher) *gocrest.Matcher

Checks whether the nth element of the array/slice matches the nth expectation passed Panics if the actual is not an array/slice Panics if the count of the expectations does not match the array's/slice's length

func FieldNamed

func FieldNamed(expected string) *gocrest.Matcher

FieldNamed is a naive implementation for testing if a struct has a particular field name. Does not check type. Returns a matcher that will use reflect to check if the actual has the method given by expected

func FunctionNamed

func FunctionNamed(expected string) *gocrest.Matcher

FunctionNamed implementation for testing if a Type has a particular method name. Does not check parameters. Returns a matcher that will use reflect to check if the actual has the method given by expected.

func Key

func Key(expected interface{}) *gocrest.Matcher

Key is a matcher that checks if actual has a key == expected. Panics when actual's Kind is not a map. Returns a matcher that matches when a map has key == expected

func Length

func Length(expected interface{}) *gocrest.Matcher

Length can be called with arrays, maps, *gocrest.Matcher and strings but not numeric types. has.Length(is.GreaterThan(x)) is a valid call. Returns a matcher that matches if the length matches the given criteria

func Prefix

func Prefix(expected string) *gocrest.Matcher

Prefix returns a matcher that matches if the given string is prefixed with the expected string Function panics if the actual is not a string. Uses strings.Prefix(act, exp) to evaluate strings. Returns a matcher that returns true if the above conditions are met

func StructWithValues added in v1.0.5

func StructWithValues(expects StructMatchers) *gocrest.Matcher

Checks whether the actual struct matches all expectations passed as StructMatchers. This method can be used to check single struct fields in different ways or omit checking some struct fields at all. Panics if the actual value is not a struct. Panics if Structmatchers contains a key that can not be found in the actual struct. Panics if Structmatchers contains a key that is unexported.

func Suffix

func Suffix(expected string) *gocrest.Matcher

Suffix returns a matcher that matches if the given string is suffixed with the expected string. Panics if the actual is not a string. Uses strings.HasSuffix(act,exp) to evaluate strings. Returns a matcher that returns true if the above conditions are met.

func TypeName added in v1.0.3

func TypeName(expected interface{}) *gocrest.Matcher

TypeName returns true if the expected matches the actual Type's Name. Expected can be a matcher or a string. E.g. has.TypeName(EqualTo("pkg.Type")) would be true with instance of `type Type struct{}` in package name 'pkg'.

Types

type StructMatchers added in v1.0.5

type StructMatchers map[string]*gocrest.Matcher

Type that can be passed to StructWithValues. Mapps Struct field names to a matcher

Jump to

Keyboard shortcuts

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