assert

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ShouldBeNil              = NewUnaryAssertion(Nil)
	ShouldBeError            = NewUnaryAssertion(Error)
	ShouldNotBeNil           = NewUnaryAssertion(NotNil)
	ShouldBeDiagnosticError  = NewBinaryAssertion(DiagnosticError)
	ShouldBeDiagnosticErrors = NewBinaryAssertion(DiagnosticErrors)
	ShouldEqual              = NewBinaryAssertion(Equal)
	ShouldHaveSameItems      = NewBinaryAssertion(HaveSameItems)
	ShouldEqualJSON          = NewBinaryAssertion(EqualJSON)
	ShouldNotReach           = func(t *testing.T, _ any, _ ...any) {
		t.Helper()

		t.Fatal("this assertion should not be reached")
	}
)

Functions

func DiagnosticError

func DiagnosticError(a, e any) error

func DiagnosticErrors

func DiagnosticErrors(a, e any) error

func Equal

func Equal(actual, expected any) error

func EqualJSON

func EqualJSON(actual, expected any) error

EqualJSON compares actual and expected by JSON-encoding both values. This normalizes numeric types (e.g., int vs float64) and map ordering.

func Error

func Error(actual any) error

func Expect

func Expect(t *testing.T, fn Binary, actual, expected any, desc ...string)

func ExpectThat

func ExpectThat(t *testing.T, fn Unary, actual any, desc ...string)

func HaveSameItems

func HaveSameItems(actual, expected any) error

func IsSameAssertion

func IsSameAssertion(a, b Assertion) bool

func Nil

func Nil(actual any) error

func NotNil

func NotNil(actual any) error

Types

type Assertion

type Assertion func(t *testing.T, actual any, other ...any)

func NewBinaryAssertion

func NewBinaryAssertion(check Binary) Assertion

func NewUnaryAssertion

func NewUnaryAssertion(check Unary) Assertion

type Binary

type Binary func(actual, expected any) error

func ComposeBinary

func ComposeBinary(checks ...Binary) Binary

type ExpectedError

type ExpectedError struct {
	Message string
	Kind    diagnostics.Kind
	Hint    string
	Format  string
}

func CastExpectedError

func CastExpectedError(err any) (*ExpectedError, bool)

type ExpectedMultiError

type ExpectedMultiError struct {
	Errors []*ExpectedError
	Number int
}

func CastExpectedMultiError

func CastExpectedMultiError(err any) (*ExpectedMultiError, bool)

type Unary

type Unary func(actual any) error

func ComposeUnary

func ComposeUnary(checks ...Unary) Unary

Jump to

Keyboard shortcuts

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