Documentation
¶
Overview ¶
Package enums helps you find instances when you find cases where you have not updated code to handle all enums you have. This is not a fully automated like exhaustive(https://github.com/nishanths/exhaustive) but rather intended to be used in cases where you might want to apply your own logic while still being warned when new cases pop up.
Enums supports basic literals and structs tagged with `enum:"identifier"`.
The entry point for enums is the All function which takes a package path and a type and will return a Collection of found instances of that type. A collection can produce a Diff given a slice of objects.
There is a helper for the standard case of "match all of this type" in enumstest.NoDiff.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
Type string // the import path of the type
FieldName string // if the underlying type is a struct this value is the name of the field that is used to distinguish flags
Enums []Enum // all distinct values found
}
Collection contains found matches from All and can be diffed against values.
func All ¶
func All(pkg string, typ string) (Collection, error)
All finds variables of typ in pkg.
Example:
All("./feature", "feature.Flag")
func (Collection) Diff ¶
func (c Collection) Diff(actual interface{}) Diff
Diff indicates differences between a collection and any slice.
Because a Collection stores all values as strings the difference is calculated based on the string representation of the value.