gen

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gen provides shared rapid generators for property-based tests.

Generators produce random struct types, tag sets, and field types for use in validation and Define() property tests.

Index

Constants

This section is empty.

Variables

Supported field types for generation.

Functions

func BuildStructType

func BuildStructType(specs []FieldSpec) reflect.Type

BuildStructType creates a reflect.Type from field specs.

func FieldType

func FieldType() *rapid.Generator[reflect.Type]

FieldType draws a random supported field type.

func InvalidBoolTagValue

func InvalidBoolTagValue() *rapid.Generator[string]

InvalidBoolTagValue draws a string that is NOT a valid boolean.

func IsValidFlagNameCheck

func IsValidFlagNameCheck(name string) bool

IsValidFlagNameCheck checks if a string matches the valid flag name regex. Duplicated here to avoid importing internal/tag from the gen package.

func NewStructValue

func NewStructValue(typ reflect.Type) any

NewStructValue creates a zero-valued pointer to a struct of the given type.

func UniqueFieldSpecs

func UniqueFieldSpecs(maxFields int) *rapid.Generator[[]FieldSpec]

UniqueFieldSpecs generates 1–maxFields field specs with unique valid flag names.

func ValidFlagName

func ValidFlagName() *rapid.Generator[string]

ValidFlagName produces strings matching ^[a-zA-Z0-9]+([.-][a-zA-Z0-9]+)*$.

func ValidTagSet

func ValidTagSet(flagName string) *rapid.Generator[TagSet]

ValidTagSet generates a well-formed tag set with no conflicts. The flagName parameter is used as the flag alias if non-empty.

Types

type FieldSpec

type FieldSpec struct {
	Name string
	Type reflect.Type
	Tags TagSet
}

FieldSpec describes a generated struct field.

type TagSet

type TagSet struct {
	Flag         string // flag alias (may be empty)
	FlagShort    string // single char shorthand
	FlagDescr    string
	FlagGroup    string
	FlagHidden   string // "true" or "false" or ""
	FlagRequired string // "true" or "false" or ""
	FlagIgnore   string // "true" or "false" or ""
	FlagCustom   string // "true" or "false" or ""
	FlagEnv      string // "true", "false", "only", or ""
	FlagPreset   string
	Default      string
}

TagSet represents a set of struct tags for a single field.

func (TagSet) ToStructTag

func (ts TagSet) ToStructTag() reflect.StructTag

ToStructTag converts a TagSet to a reflect.StructTag string. Values must not contain '"' or '\\' — these break struct tag encoding and cause Tag.Get to return truncated or empty results.

Jump to

Keyboard shortcuts

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