test

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package test contains testing types and scenarios.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is returned when the length of the input data is invalid.
	ErrInvalidLength = errors.New("invalid length")
)

Functions

This section is empty.

Types

type FullMsgpackExtType

type FullMsgpackExtType struct {
	A int
	B string
}

FullMsgpackExtType is a test type with both MarshalMsgpack and UnmarshalMsgpack methods.

func NewEmptyFullMsgpackExtType

func NewEmptyFullMsgpackExtType() (out FullMsgpackExtType)

NewEmptyFullMsgpackExtType is an empty constructor for FullMsgpackExtType.

func (*FullMsgpackExtType) MarshalMsgpack

func (t *FullMsgpackExtType) MarshalMsgpack() ([]byte, error)

MarshalMsgpack .

func (*FullMsgpackExtType) UnmarshalMsgpack

func (t *FullMsgpackExtType) UnmarshalMsgpack(in []byte) error

UnmarshalMsgpack .

type HiddenTypeAlias

type HiddenTypeAlias = subpackage.Hidden

HiddenTypeAlias is a hidden type alias to test.

type OptionalFullMsgpackExtType

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

OptionalFullMsgpackExtType represents an optional value of type FullMsgpackExtType. It can either hold a valid FullMsgpackExtType (IsSome == true) or be empty (IsZero == true).

func NoneOptionalFullMsgpackExtType

func NoneOptionalFullMsgpackExtType() OptionalFullMsgpackExtType

NoneOptionalFullMsgpackExtType creates an empty optional OptionalFullMsgpackExtType value. The returned OptionalFullMsgpackExtType will have IsSome() == false and IsZero() == true.

Example:

o := NoneOptionalFullMsgpackExtType()
if o.IsZero() {
    fmt.Println("value is absent")
}

func SomeOptionalFullMsgpackExtType

func SomeOptionalFullMsgpackExtType(value FullMsgpackExtType) OptionalFullMsgpackExtType

SomeOptionalFullMsgpackExtType creates an optional OptionalFullMsgpackExtType with the given FullMsgpackExtType value. The returned OptionalFullMsgpackExtType will have IsSome() == true and IsZero() == false.

func (*OptionalFullMsgpackExtType) DecodeMsgpack

func (o *OptionalFullMsgpackExtType) DecodeMsgpack(decoder *msgpack.Decoder) error

DecodeMsgpack decodes a OptionalFullMsgpackExtType value from MessagePack format. Supports two input types:

  • nil: interpreted as no value (NoneOptionalFullMsgpackExtType)
  • FullMsgpackExtType: interpreted as a present value (SomeOptionalFullMsgpackExtType)

Returns an error if the input type is unsupported or decoding fails.

After successful decoding:

  • on nil: exists = false, value = default zero value
  • on FullMsgpackExtType: exists = true, value = decoded value

func (OptionalFullMsgpackExtType) EncodeMsgpack

func (o OptionalFullMsgpackExtType) EncodeMsgpack(encoder *msgpack.Encoder) error

EncodeMsgpack encodes the OptionalFullMsgpackExtType value using MessagePack format. - If the value is present, it is encoded as FullMsgpackExtType. - If the value is absent (None), it is encoded as nil.

Returns an error if encoding fails.

func (OptionalFullMsgpackExtType) Get

Get returns the stored value and a boolean flag indicating its presence. If the value is present, returns (value, true). If the value is absent, returns (zero value of FullMsgpackExtType, false).

Recommended usage:

	if value, ok := o.Get(); ok {
     // use value
	}

func (OptionalFullMsgpackExtType) IsNil

func (o OptionalFullMsgpackExtType) IsNil() bool

IsNil is an alias for IsZero.

This method is provided for compatibility with the msgpack Encoder interface.

func (OptionalFullMsgpackExtType) IsSome

func (o OptionalFullMsgpackExtType) IsSome() bool

IsSome returns true if the OptionalFullMsgpackExtType contains a value. This indicates the value is explicitly set (not None).

func (OptionalFullMsgpackExtType) IsZero

func (o OptionalFullMsgpackExtType) IsZero() bool

IsZero returns true if the OptionalFullMsgpackExtType does not contain a value. Equivalent to !IsSome(). Useful for consistency with types where zero value (e.g. 0, false, zero struct) is valid and needs to be distinguished.

func (OptionalFullMsgpackExtType) MustGet

MustGet returns the stored value if it is present. Panics if the value is absent (i.e., IsZero() == true).

Use with caution — only when you are certain the value exists.

Panics with: "optional value is not set" if no value is set.

func (OptionalFullMsgpackExtType) Unwrap

Unwrap returns the stored value regardless of presence. If no value is set, returns the zero value for FullMsgpackExtType.

Warning: Does not check presence. Use IsSome() before calling if you need to distinguish between absent value and explicit zero value.

func (OptionalFullMsgpackExtType) UnwrapOr

UnwrapOr returns the stored value if present. Otherwise, returns the provided default value.

Example:

o := NoneOptionalFullMsgpackExtType()
v := o.UnwrapOr(someDefaultOptionalFullMsgpackExtType)

func (OptionalFullMsgpackExtType) UnwrapOrElse

func (o OptionalFullMsgpackExtType) UnwrapOrElse(defaultValue func() FullMsgpackExtType) FullMsgpackExtType

UnwrapOrElse returns the stored value if present. Otherwise, calls the provided function and returns its result. Useful when the default value requires computation or side effects.

Example:

o := NoneOptionalFullMsgpackExtType()
v := o.UnwrapOrElse(func() FullMsgpackExtType { return computeDefault() })

type OptionalHiddenTypeAlias

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

OptionalHiddenTypeAlias represents an optional value of type HiddenTypeAlias. It can either hold a valid HiddenTypeAlias (IsSome == true) or be empty (IsZero == true).

func NoneOptionalHiddenTypeAlias

func NoneOptionalHiddenTypeAlias() OptionalHiddenTypeAlias

NoneOptionalHiddenTypeAlias creates an empty optional OptionalHiddenTypeAlias value. The returned OptionalHiddenTypeAlias will have IsSome() == false and IsZero() == true.

Example:

o := NoneOptionalHiddenTypeAlias()
if o.IsZero() {
    fmt.Println("value is absent")
}

func SomeOptionalHiddenTypeAlias

func SomeOptionalHiddenTypeAlias(value HiddenTypeAlias) OptionalHiddenTypeAlias

SomeOptionalHiddenTypeAlias creates an optional OptionalHiddenTypeAlias with the given HiddenTypeAlias value. The returned OptionalHiddenTypeAlias will have IsSome() == true and IsZero() == false.

func (*OptionalHiddenTypeAlias) DecodeMsgpack

func (o *OptionalHiddenTypeAlias) DecodeMsgpack(decoder *msgpack.Decoder) error

DecodeMsgpack decodes a OptionalHiddenTypeAlias value from MessagePack format. Supports two input types:

  • nil: interpreted as no value (NoneOptionalHiddenTypeAlias)
  • HiddenTypeAlias: interpreted as a present value (SomeOptionalHiddenTypeAlias)

Returns an error if the input type is unsupported or decoding fails.

After successful decoding:

  • on nil: exists = false, value = default zero value
  • on HiddenTypeAlias: exists = true, value = decoded value

func (OptionalHiddenTypeAlias) EncodeMsgpack

func (o OptionalHiddenTypeAlias) EncodeMsgpack(encoder *msgpack.Encoder) error

EncodeMsgpack encodes the OptionalHiddenTypeAlias value using MessagePack format. - If the value is present, it is encoded as HiddenTypeAlias. - If the value is absent (None), it is encoded as nil.

Returns an error if encoding fails.

func (OptionalHiddenTypeAlias) Get

Get returns the stored value and a boolean flag indicating its presence. If the value is present, returns (value, true). If the value is absent, returns (zero value of HiddenTypeAlias, false).

Recommended usage:

	if value, ok := o.Get(); ok {
     // use value
	}

func (OptionalHiddenTypeAlias) IsNil

func (o OptionalHiddenTypeAlias) IsNil() bool

IsNil is an alias for IsZero.

This method is provided for compatibility with the msgpack Encoder interface.

func (OptionalHiddenTypeAlias) IsSome

func (o OptionalHiddenTypeAlias) IsSome() bool

IsSome returns true if the OptionalHiddenTypeAlias contains a value. This indicates the value is explicitly set (not None).

func (OptionalHiddenTypeAlias) IsZero

func (o OptionalHiddenTypeAlias) IsZero() bool

IsZero returns true if the OptionalHiddenTypeAlias does not contain a value. Equivalent to !IsSome(). Useful for consistency with types where zero value (e.g. 0, false, zero struct) is valid and needs to be distinguished.

func (OptionalHiddenTypeAlias) MustGet

MustGet returns the stored value if it is present. Panics if the value is absent (i.e., IsZero() == true).

Use with caution — only when you are certain the value exists.

Panics with: "optional value is not set" if no value is set.

func (OptionalHiddenTypeAlias) Unwrap

Unwrap returns the stored value regardless of presence. If no value is set, returns the zero value for HiddenTypeAlias.

Warning: Does not check presence. Use IsSome() before calling if you need to distinguish between absent value and explicit zero value.

func (OptionalHiddenTypeAlias) UnwrapOr

func (o OptionalHiddenTypeAlias) UnwrapOr(defaultValue HiddenTypeAlias) HiddenTypeAlias

UnwrapOr returns the stored value if present. Otherwise, returns the provided default value.

Example:

o := NoneOptionalHiddenTypeAlias()
v := o.UnwrapOr(someDefaultOptionalHiddenTypeAlias)

func (OptionalHiddenTypeAlias) UnwrapOrElse

func (o OptionalHiddenTypeAlias) UnwrapOrElse(defaultValue func() HiddenTypeAlias) HiddenTypeAlias

UnwrapOrElse returns the stored value if present. Otherwise, calls the provided function and returns its result. Useful when the default value requires computation or side effects.

Example:

o := NoneOptionalHiddenTypeAlias()
v := o.UnwrapOrElse(func() HiddenTypeAlias { return computeDefault() })

type OptionalUUID

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

OptionalUUID represents an optional value of type uuid.UUID. It can either hold a valid uuid.UUID (IsSome == true) or be empty (IsZero == true).

func NoneOptionalUUID

func NoneOptionalUUID() OptionalUUID

NoneOptionalUUID creates an empty optional OptionalUUID value. The returned OptionalUUID will have IsSome() == false and IsZero() == true.

Example:

o := NoneOptionalUUID()
if o.IsZero() {
    fmt.Println("value is absent")
}

func SomeOptionalUUID

func SomeOptionalUUID(value uuid.UUID) OptionalUUID

SomeOptionalUUID creates an optional OptionalUUID with the given uuid.UUID value. The returned OptionalUUID will have IsSome() == true and IsZero() == false.

func (*OptionalUUID) DecodeMsgpack

func (o *OptionalUUID) DecodeMsgpack(decoder *msgpack.Decoder) error

DecodeMsgpack decodes a OptionalUUID value from MessagePack format. Supports two input types:

  • nil: interpreted as no value (NoneOptionalUUID)
  • uuid.UUID: interpreted as a present value (SomeOptionalUUID)

Returns an error if the input type is unsupported or decoding fails.

After successful decoding:

  • on nil: exists = false, value = default zero value
  • on uuid.UUID: exists = true, value = decoded value

func (OptionalUUID) EncodeMsgpack

func (o OptionalUUID) EncodeMsgpack(encoder *msgpack.Encoder) error

EncodeMsgpack encodes the OptionalUUID value using MessagePack format. - If the value is present, it is encoded as uuid.UUID. - If the value is absent (None), it is encoded as nil.

Returns an error if encoding fails.

func (OptionalUUID) Get

func (o OptionalUUID) Get() (uuid.UUID, bool)

Get returns the stored value and a boolean flag indicating its presence. If the value is present, returns (value, true). If the value is absent, returns (zero value of uuid.UUID, false).

Recommended usage:

	if value, ok := o.Get(); ok {
     // use value
	}

func (OptionalUUID) IsNil

func (o OptionalUUID) IsNil() bool

IsNil is an alias for IsZero.

This method is provided for compatibility with the msgpack Encoder interface.

func (OptionalUUID) IsSome

func (o OptionalUUID) IsSome() bool

IsSome returns true if the OptionalUUID contains a value. This indicates the value is explicitly set (not None).

func (OptionalUUID) IsZero

func (o OptionalUUID) IsZero() bool

IsZero returns true if the OptionalUUID does not contain a value. Equivalent to !IsSome(). Useful for consistency with types where zero value (e.g. 0, false, zero struct) is valid and needs to be distinguished.

func (OptionalUUID) MustGet

func (o OptionalUUID) MustGet() uuid.UUID

MustGet returns the stored value if it is present. Panics if the value is absent (i.e., IsZero() == true).

Use with caution — only when you are certain the value exists.

Panics with: "optional value is not set" if no value is set.

func (OptionalUUID) Unwrap

func (o OptionalUUID) Unwrap() uuid.UUID

Unwrap returns the stored value regardless of presence. If no value is set, returns the zero value for uuid.UUID.

Warning: Does not check presence. Use IsSome() before calling if you need to distinguish between absent value and explicit zero value.

func (OptionalUUID) UnwrapOr

func (o OptionalUUID) UnwrapOr(defaultValue uuid.UUID) uuid.UUID

UnwrapOr returns the stored value if present. Otherwise, returns the provided default value.

Example:

o := NoneOptionalUUID()
v := o.UnwrapOr(someDefaultOptionalUUID)

func (OptionalUUID) UnwrapOrElse

func (o OptionalUUID) UnwrapOrElse(defaultValue func() uuid.UUID) uuid.UUID

UnwrapOrElse returns the stored value if present. Otherwise, calls the provided function and returns its result. Useful when the default value requires computation or side effects.

Example:

o := NoneOptionalUUID()
v := o.UnwrapOrElse(func() uuid.UUID { return computeDefault() })

Directories

Path Synopsis
Package subpackage contains a hidden type for testing type aliases generation.
Package subpackage contains a hidden type for testing type aliases generation.

Jump to

Keyboard shortcuts

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