psi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package psi contains helpers that extends gomega library Name psi stands for previous letter from Omega (as we want to have a name that is close to gomega, but not to be a gomega)

Package psi is considered as internal package to be used only inside `be` It's a core functionality that upgrades any matcher to be a `be` matcher Also it contains some core matchers and upgraded things from `gomega/gcustom` package

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExpectedStr2LinesRegex matches first 2 lines of standard gomega failure message
	ExpectedStr2LinesRegex = regexp.MustCompile(`Expected\n.*\n`)
)

Functions

func AsMatchFunc added in v0.2.0

func AsMatchFunc(m any) func(any) (bool, error)

func AsMatcher

func AsMatcher(m any) types.BeMatcher

AsMatcher returns BeMatcher that is made from given input

func FromGomega

func FromGomega(omega types.GomegaMatcher, messagePrefixArg ...string) types.BeMatcher

func FromGomock

func FromGomock(m types.GomockMatcher) types.BeMatcher

func IsMatchFunc added in v0.2.0

func IsMatchFunc(m any) bool

func IsMatcher

func IsMatcher(a any) bool

IsMatcher returns true if given input is either Omega or Gomock or a Psi matcher

func IsTransformFunc

func IsTransformFunc(v any) bool

IsTransformFunc checks if given thing is a Gomega-compatible transform For v to be a transform it must be a function of one parameter that returns one value and an optional error

func Psi

func Psi(args ...any) types.BeMatcher

Psi is a main converter function that converts given input into a PsiMatcher

func WithFallibleTransform

func WithFallibleTransform(transform any, matcher gomega.OmegaMatcher) types.BeMatcher

WithFallibleTransform creates a gomega transform matcher that can nicely handle failures Also it allows to have nil matcher, meaning that we're OK unless transform failed

Types

type DiveMatcher added in v0.2.0

type DiveMatcher struct {
	*MixinMatcherGomock
	// contains filtered or unexported fields
}

func NewDiveMatcher added in v0.2.0

func NewDiveMatcher(matcher any, mode DiveMode) *DiveMatcher

func (*DiveMatcher) FailureMessage added in v0.2.0

func (dm *DiveMatcher) FailureMessage(actual any) string

func (*DiveMatcher) Match added in v0.2.0

func (dm *DiveMatcher) Match(actual interface{}) (bool, error)

func (*DiveMatcher) NegatedFailureMessage added in v0.2.0

func (dm *DiveMatcher) NegatedFailureMessage(actual any) string

type DiveMode added in v0.2.0

type DiveMode string
const (
	DiveModeEvery DiveMode = "every"
	DiveModeAny   DiveMode = "any"
	DiveModeFirst DiveMode = "first"
)

type MixinMatcherGomock

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

MixinMatcherGomock should be used for embedding to create a matcher that fits Gomock interface

func NewMixinMatcherGomock

func NewMixinMatcherGomock(Ω types.GomegaMatcher, messagePrefixArg ...string) *MixinMatcherGomock

func (*MixinMatcherGomock) Matches

func (igm *MixinMatcherGomock) Matches(v any) bool

func (*MixinMatcherGomock) String

func (igm *MixinMatcherGomock) String() string

type TransformError

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

TransformError is used to store error + actual value which caused the error

func NewTransformError

func NewTransformError(err error, actual any) *TransformError

func (*TransformError) Actual

func (terr *TransformError) Actual() any

type TransformErrorMatcher

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

TransformErrorMatcher is actually a matcher

func WithTransformError

func WithTransformError() *TransformErrorMatcher

func (*TransformErrorMatcher) FailureMessage

func (matcher *TransformErrorMatcher) FailureMessage(actual any) string

func (*TransformErrorMatcher) Match

func (matcher *TransformErrorMatcher) Match(actual any) (success bool, err error)

func (*TransformErrorMatcher) NegatedFailureMessage

func (matcher *TransformErrorMatcher) NegatedFailureMessage(actual any) string

Jump to

Keyboard shortcuts

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