contract

package
v0.0.0-...-5f65a09 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorViolatedInvariant = errors.New("violated invariant")
)
View Source
var FulfilledfulConditionEvaluation = ConditionEvaluation{
	// contains filtered or unexported fields
}

FulfilledfulConditionEvaluation is the result of a condition that was fullfilled.

Functions

func Evaluate

func Evaluate(expression bool, errorFormat string, param ...any) error

Evaluates evaluates an inline condition.

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

type Condition[T any] func(T) error

Condition are used to capture assumptions on objects. When a condition is not fulfilled it resturns an error.

func (Condition[T]) And

func (c Condition[T]) And(other Condition[T]) Condition[T]

And is used to combine the condition with an other. The resulting condition is fulfilled if both conditions are fulfilled.

func (Condition[T]) Or

func (c Condition[T]) Or(other Condition[T]) Condition[T]

Or is used to combine the condition with an other. The resulting condition is fulfilled if one of the two conditions is fulfilled.

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.

Jump to

Keyboard shortcuts

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