enumer/testdata/num.golden

93 lines
2.0 KiB
Plaintext
Raw Normal View History

2020-08-09 07:14:17 +03:00
const _NumName = "m_2m_1m0m1m2"
var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12}
const _NumLowerName = "m_2m_1m0m1m2"
2023-04-10 22:37:44 +03:00
func (i Num) string() (string, error) {
2020-08-09 07:14:17 +03:00
i -= -2
if i < 0 || i >= Num(len(_NumIndex)-1) {
2023-04-10 22:37:44 +03:00
return "", fmt.Errorf("value is out of enum range")
2020-08-09 07:14:17 +03:00
}
2023-04-10 22:37:44 +03:00
return _NumName[_NumIndex[i]:_NumIndex[i+1]], nil
}
func (i Num) String() string {
val, _ := i.string()
return val
2020-08-09 07:14:17 +03:00
}
2021-10-17 15:31:43 +03:00
func (Num) Values() []string {
return NumStrings()
}
2020-08-09 07:14:17 +03:00
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _NumNoOp() {
var x [1]struct{}
_ = x[m_2-(-2)]
_ = x[m_1-(-1)]
_ = x[m0-(0)]
_ = x[m1-(1)]
_ = x[m2-(2)]
}
var _NumValues = []Num{m_2, m_1, m0, m1, m2}
var _NumNameToValueMap = map[string]Num{
_NumName[0:3]: m_2,
_NumLowerName[0:3]: m_2,
_NumName[3:6]: m_1,
_NumLowerName[3:6]: m_1,
_NumName[6:8]: m0,
_NumLowerName[6:8]: m0,
_NumName[8:10]: m1,
_NumLowerName[8:10]: m1,
_NumName[10:12]: m2,
_NumLowerName[10:12]: m2,
}
var _NumNames = []string{
_NumName[0:3],
_NumName[3:6],
_NumName[6:8],
_NumName[8:10],
_NumName[10:12],
}
// NumString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func NumString(s string) (Num, error) {
if val, ok := _NumNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _NumNameToValueMap[strings.ToLower(s)]; ok {
2020-08-09 07:14:17 +03:00
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Num values", s)
}
// NumValues returns all values of the enum
func NumValues() []Num {
return _NumValues
}
// NumStrings returns a slice of all String values of the enum
func NumStrings() []string {
strs := make([]string, len(_NumNames))
copy(strs, _NumNames)
return strs
}
// IsANum returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Num) IsANum() bool {
for _, v := range _NumValues {
if i == v {
return true
}
}
return false
}