be_reflected

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

README

be_reflected

-- import "github.com/expectto/be/be_reflected"

Package be_reflected provides Be matchers that use reflection, enabling expressive assertions on values' reflect kinds and types. It consists of several "core" matchers e.g. AsKind / AssignableTo / Implementing And many other matchers that are made on-top on core ones. E.g. AsFunc / AsString / AsNumber /

etc

Usage

func AsBytes
func AsBytes() types.BeMatcher

AsBytes succeeds if actual is assignable to a slice of bytes ([]byte).

func AsChan
func AsChan() types.BeMatcher

AsChan succeeds if actual is of kind reflect.Chan.

func AsFinalPointer
func AsFinalPointer() types.BeMatcher

AsFinalPointer succeeds if the actual value is a final pointer, meaning it's a pointer to a non-pointer type.

func AsFloat
func AsFloat() types.BeMatcher

AsFloat succeeds if actual is a numeric value that represents a floating-point value.

func AsFloatString
func AsFloatString() types.BeMatcher

AsFloatString succeeds if actual is a string that can be parsed into a valid floating-point value.

func AsFunc
func AsFunc() types.BeMatcher

AsFunc succeeds if actual is of kind reflect.Func.

func AsInteger
func AsInteger() types.BeMatcher

AsInteger succeeds if actual is a numeric value that represents an integer (from reflect.Int up to reflect.Uint64).

func AsIntegerString
func AsIntegerString() types.BeMatcher

AsIntegerString succeeds if actual is a string that can be parsed into a valid integer value.

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

AsKind succeeds if actual is assignable to any of the specified kinds or matches the provided matchers.

func AsMap
func AsMap() types.BeMatcher

AsMap succeeds if actual is of kind reflect.Map.

func AsNumber
func AsNumber() types.BeMatcher

AsNumber succeeds if actual is a numeric value, supporting various integer kinds: reflect.Int, ... reflect.Int64, and floating-point kinds: reflect.Float32, reflect.Float64

func AsNumericString
func AsNumericString() types.BeMatcher

AsNumericString succeeds if actual is a string that can be parsed into a valid numeric value.

func AsObject
func AsObject() types.BeMatcher

AsObject is more specific than AsMap. It checks if the given actual value is a map with string keys and values of any type. This is particularly useful in the context of BeJson matcher, where the term 'Object' aligns with JSON notation.

func AsObjects
func AsObjects() types.BeMatcher
func AsPointer
func AsPointer() types.BeMatcher

AsPointer succeeds if the actual value is a pointer.

func AsPointerToMap
func AsPointerToMap() types.BeMatcher

AsPointerToMap succeeds if actual is a pointer to a map.

func AsPointerToObject
func AsPointerToObject() types.BeMatcher

AsPointerToObject succeeds if actual is a pointer to a value that matches AsObject after applying dereference.

func AsPointerToSlice
func AsPointerToSlice() types.BeMatcher

AsPointerToSlice succeeds if actual is a pointer to a slice.

func AsPointerToStruct
func AsPointerToStruct() types.BeMatcher

AsPointerToStruct succeeds if actual is a pointer to a struct.

func AsReader
func AsReader() types.BeMatcher

AsReader succeeds if actual implements the io.Reader interface.

func AsSlice
func AsSlice() types.BeMatcher

AsSlice succeeds if actual is of kind reflect.Slice.

func AsSliceOf
func AsSliceOf[T any]() types.BeMatcher

AsSliceOf succeeds if actual is of kind reflect.Slice and each element of the slice is assignable to the specified type T.

func AsString
func AsString() types.BeMatcher

AsString succeeds if actual is of kind reflect.String.

func AsStringer
func AsStringer() types.BeMatcher

AsStringer succeeds if actual implements the fmt.Stringer interface.

func AsStruct
func AsStruct() types.BeMatcher

AsStruct succeeds if actual is of kind reflect.Struct.

func AssignableTo
func AssignableTo[T any]() types.BeMatcher

AssignableTo succeeds if actual is assignable to the specified type T.

func Implementing
func Implementing[T any]() types.BeMatcher

Implementing succeeds if actual implements the specified interface type T.

Documentation

Overview

Package be_reflected provides Be matchers that use reflection, enabling expressive assertions on values' reflect kinds and types. It consists of several "core" matchers e.g. AsKind / AssignableTo / Implementing And many other matchers that are made on-top on core ones. E.g. AsFunc / AsString / AsNumber / etc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsBytes

func AsBytes() types.BeMatcher

AsBytes succeeds if actual is assignable to a slice of bytes ([]byte).

func AsChan

func AsChan() types.BeMatcher

AsChan succeeds if actual is of kind reflect.Chan.

func AsFinalPointer

func AsFinalPointer() types.BeMatcher

AsFinalPointer succeeds if the actual value is a final pointer, meaning it's a pointer to a non-pointer type.

func AsFloat added in v0.2.0

func AsFloat() types.BeMatcher

AsFloat succeeds if actual is a numeric value that represents a floating-point value.

func AsFloatString added in v0.2.0

func AsFloatString() types.BeMatcher

AsFloatString succeeds if actual is a string that can be parsed into a valid floating-point value.

func AsFunc

func AsFunc() types.BeMatcher

AsFunc succeeds if actual is of kind reflect.Func.

func AsInteger added in v0.2.0

func AsInteger() types.BeMatcher

AsInteger succeeds if actual is a numeric value that represents an integer (from reflect.Int up to reflect.Uint64).

func AsIntegerString added in v0.2.0

func AsIntegerString() types.BeMatcher

AsIntegerString succeeds if actual is a string that can be parsed into a valid integer value.

func AsKind

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

AsKind succeeds if actual is assignable to any of the specified kinds or matches the provided matchers.

func AsMap

func AsMap() types.BeMatcher

AsMap succeeds if actual is of kind reflect.Map.

func AsNumber added in v0.2.0

func AsNumber() types.BeMatcher

AsNumber succeeds if actual is a numeric value, supporting various integer kinds: reflect.Int, ... reflect.Int64, and floating-point kinds: reflect.Float32, reflect.Float64

func AsNumericString

func AsNumericString() types.BeMatcher

AsNumericString succeeds if actual is a string that can be parsed into a valid numeric value.

func AsObject

func AsObject() types.BeMatcher

AsObject is more specific than AsMap. It checks if the given `actual` value is a map with string keys and values of any type. This is particularly useful in the context of BeJson matcher, where the term 'Object' aligns with JSON notation.

func AsObjects

func AsObjects() types.BeMatcher

func AsPointer

func AsPointer() types.BeMatcher

AsPointer succeeds if the actual value is a pointer.

func AsPointerToMap

func AsPointerToMap() types.BeMatcher

AsPointerToMap succeeds if actual is a pointer to a map.

func AsPointerToObject

func AsPointerToObject() types.BeMatcher

AsPointerToObject succeeds if actual is a pointer to a value that matches AsObject after applying dereference.

func AsPointerToSlice

func AsPointerToSlice() types.BeMatcher

AsPointerToSlice succeeds if actual is a pointer to a slice.

func AsPointerToStruct

func AsPointerToStruct() types.BeMatcher

AsPointerToStruct succeeds if actual is a pointer to a struct.

func AsReader

func AsReader() types.BeMatcher

AsReader succeeds if actual implements the io.Reader interface.

func AsSlice

func AsSlice() types.BeMatcher

AsSlice succeeds if actual is of kind reflect.Slice.

func AsSliceOf

func AsSliceOf[T any]() types.BeMatcher

AsSliceOf succeeds if actual is of kind reflect.Slice and each element of the slice is assignable to the specified type T.

func AsString

func AsString() types.BeMatcher

AsString succeeds if actual is of kind reflect.String.

func AsStringer

func AsStringer() types.BeMatcher

AsStringer succeeds if actual implements the fmt.Stringer interface.

func AsStruct

func AsStruct() types.BeMatcher

AsStruct succeeds if actual is of kind reflect.Struct.

func AssignableTo

func AssignableTo[T any]() types.BeMatcher

AssignableTo succeeds if actual is assignable to the specified type T.

func Implementing

func Implementing[T any]() types.BeMatcher

Implementing succeeds if actual implements the specified interface type T.

Types

This section is empty.

Jump to

Keyboard shortcuts

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