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 ¶
- Variables
- func BuildStructType(specs []FieldSpec) reflect.Type
- func FieldType() *rapid.Generator[reflect.Type]
- func InvalidBoolTagValue() *rapid.Generator[string]
- func IsValidFlagNameCheck(name string) bool
- func NewStructValue(typ reflect.Type) any
- func UniqueFieldSpecs(maxFields int) *rapid.Generator[[]FieldSpec]
- func ValidFlagName() *rapid.Generator[string]
- func ValidTagSet(flagName string) *rapid.Generator[TagSet]
- type FieldSpec
- type TagSet
Constants ¶
This section is empty.
Variables ¶
var SupportedFieldTypes = []reflect.Type{ reflect.TypeOf(false), reflect.TypeOf(""), reflect.TypeOf(int(0)), reflect.TypeOf(int8(0)), reflect.TypeOf(int16(0)), reflect.TypeOf(int32(0)), reflect.TypeOf(int64(0)), reflect.TypeOf(uint(0)), reflect.TypeOf(uint8(0)), reflect.TypeOf(uint16(0)), reflect.TypeOf(uint32(0)), reflect.TypeOf(uint64(0)), reflect.TypeOf(float32(0)), reflect.TypeOf(float64(0)), reflect.TypeOf([]string(nil)), reflect.TypeOf([]int(nil)), }
Supported field types for generation.
Functions ¶
func BuildStructType ¶
BuildStructType creates a reflect.Type from field specs.
func InvalidBoolTagValue ¶
InvalidBoolTagValue draws a string that is NOT a valid boolean.
func IsValidFlagNameCheck ¶
IsValidFlagNameCheck checks if a string matches the valid flag name regex. Duplicated here to avoid importing internal/tag from the gen package.
func NewStructValue ¶
NewStructValue creates a zero-valued pointer to a struct of the given type.
func UniqueFieldSpecs ¶
UniqueFieldSpecs generates 1–maxFields field specs with unique valid flag names.
func ValidFlagName ¶
ValidFlagName produces strings matching ^[a-zA-Z0-9]+([.-][a-zA-Z0-9]+)*$.
Types ¶
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 ¶
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.