Documentation ¶
Index ¶
- Variables
- func Evaluate(expression bool, errorFormat string, param ...any) error
- func Immutable[T comparable](value *T) invariant
- func Invariant[T any, O comparable](i *T, property func(t T) O) invariant
- type Condition
- type ConditionEvaluation
- func Ensures(constraint bool) ConditionEvaluation
- func EnsuresThat[T any](value T, specification Condition[T]) ConditionEvaluation
- func NewConditionEvaluation(err error) ConditionEvaluation
- func Requires(constraint bool) ConditionEvaluation
- func RequiresThat[T any](value T, specification Condition[T]) ConditionEvaluation
- func (c ConditionEvaluation) AssertFulfilled(t *testing.T) bool
- func (c ConditionEvaluation) AssertUnfulfilled(t *testing.T) bool
- func (c ConditionEvaluation) ErrorOnFailure() error
- func (c ConditionEvaluation) Fulfilled() bool
- func (c ConditionEvaluation) LogOnFailure()
- func (c ConditionEvaluation) PanicOnFailure()
- func (c ConditionEvaluation) Unfulfilled() bool
Constants ¶
This section is empty.
Variables ¶
var (
ErrorViolatedInvariant = errors.New("violated invariant")
)
var FulfilledfulConditionEvaluation = ConditionEvaluation{ // contains filtered or unexported fields }
FulfilledfulConditionEvaluation is the result of a condition that was fullfilled.
Functions ¶
func Immutable ¶
func Immutable[T comparable](value *T) invariant
Immutable creates an invariant that check that the value is immutable.
func Invariant ¶
func Invariant[T any, O comparable](i *T, property func(t T) O) invariant
Invariant is an invariant for a given type.
Types ¶
type Condition ¶
Condition are used to capture assumptions on objects. When a condition is not fulfilled it resturns an error.
type ConditionEvaluation ¶
type ConditionEvaluation struct {
// contains filtered or unexported fields
}
ConditionEvaluation represents the result when a condition is evaluated.
func Ensures ¶
func Ensures(constraint bool) ConditionEvaluation
Ensures is used to impose a postcondition using an expression.
func EnsuresThat ¶
func EnsuresThat[T any](value T, specification Condition[T]) ConditionEvaluation
EnsuresThat is used to impose a postcondition on a type using a condition.
func NewConditionEvaluation ¶
func NewConditionEvaluation(err error) ConditionEvaluation
NewConditionEvaluation creates a condition evaluation.
func Requires ¶
func Requires(constraint bool) ConditionEvaluation
Requires is used to impose a precondition using an expression.
func RequiresThat ¶
func RequiresThat[T any](value T, specification Condition[T]) ConditionEvaluation
RequiresThat is used to impose a precondition on a type using a condition.
func (ConditionEvaluation) AssertFulfilled ¶
func (c ConditionEvaluation) AssertFulfilled(t *testing.T) bool
AssertFulfilled asserts that the condition is fulfilled.
func (ConditionEvaluation) AssertUnfulfilled ¶
func (c ConditionEvaluation) AssertUnfulfilled(t *testing.T) bool
AssertUnulfilled asserts that the condition is unfulfilled.
func (ConditionEvaluation) ErrorOnFailure ¶
func (c ConditionEvaluation) ErrorOnFailure() error
ErrorOnFailure will return an error if the condition is unfulfilled.
func (ConditionEvaluation) Fulfilled ¶
func (c ConditionEvaluation) Fulfilled() bool
Fulfilled returns true if the condition was fulfilled.
func (ConditionEvaluation) LogOnFailure ¶
func (c ConditionEvaluation) LogOnFailure()
LogOnFailure will log the error if the condition is unfulfilled.
func (ConditionEvaluation) PanicOnFailure ¶
func (c ConditionEvaluation) PanicOnFailure()
PanicOnFailure will panic if the condition is unfulfilled.
func (ConditionEvaluation) Unfulfilled ¶
func (c ConditionEvaluation) Unfulfilled() bool
Unfulfilled returns true if the condition was unfulfilled.