enum

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package enum implements the enum generator for testkit. It scans const blocks of named types and generates exhaustiveness, distinctness, and stringer tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	PackageName  string
	ImportPath   string // source package import path (empty if same package)
	PkgQualifier string // "store" or "" for same package
	Enums        []TypeData
}

Data is the top-level template data for an enum generation run.

func Analyze

func Analyze(
	pkg *gen.Package,
	args []string,
	cfg gen.Config,
	opts gen.Options,
) (*Data, error)

Analyze builds Data by scanning the package for const blocks of the given named types.

func (*Data) HasContent

func (d *Data) HasContent() bool

HasContent reports whether there are any enums to test.

func (*Data) HasJSON

func (d *Data) HasJSON() bool

HasJSON reports whether any enum implements MarshalJSON/UnmarshalJSON.

func (*Data) HasStringer

func (d *Data) HasStringer() bool

HasStringer reports whether any enum has a String() method.

type Generator

type Generator struct{}

Generator produces exhaustiveness tests for Go enum types.

func (*Generator) Generate

func (*Generator) Generate(
	pkg *gen.Package,
	args []string,
	cfg gen.Config,
	opts gen.Options,
) (*gen.Result, error)

Generate scans const blocks for the given type names and produces a test file with exhaustiveness, distinctness, and stringer tests.

func (*Generator) Name

func (*Generator) Name() string

Name returns "enum".

type TypeData

type TypeData struct {
	TypeName       string  // "Status"
	Values         []Value // sorted by name
	MaxValue       int64   // highest iota value for boundary test
	HasString      bool    // true if the type has a String() string method
	HasParse       bool    // true if Parse<Type>(string) (<Type>, error) exists
	ParseFunc      string  // "ParseStatus"
	HasMarshalText bool    // true if the type implements encoding.TextMarshaler/TextUnmarshaler
	HasMarshalJSON bool    // true if the type implements json.Marshaler/json.Unmarshaler
	ZeroValueName  string  // "StatusPending" — the constant with IntValue == 0
}

TypeData holds one enum type and its constant values.

type Value

type Value struct {
	Name        string // "StatusPending"
	ExpectedStr string // "Pending" — inline comment or derived name
	IntValue    int64
}

Value holds one constant of an enum type.

Jump to

Keyboard shortcuts

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