enumer/testdata/unum.golden

94 lines
2.1 KiB
Plaintext

const (
_UnumName_0 = "m0m1m2"
_UnumLowerName_0 = "m0m1m2"
_UnumName_1 = "m_2m_1"
_UnumLowerName_1 = "m_2m_1"
)
var (
_UnumIndex_0 = [...]uint8{0, 2, 4, 6}
_UnumIndex_1 = [...]uint8{0, 3, 6}
)
func (i Unum) String() string {
switch {
case 0 <= i && i <= 2:
return _UnumName_0[_UnumIndex_0[i]:_UnumIndex_0[i+1]]
case 253 <= i && i <= 254:
i -= 253
return _UnumName_1[_UnumIndex_1[i]:_UnumIndex_1[i+1]]
default:
return fmt.Sprintf("Unum(%d)", i)
}
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _UnumNoOp() {
var x [1]struct{}
_ = x[m0-(0)]
_ = x[m1-(1)]
_ = x[m2-(2)]
_ = x[m_2-(253)]
_ = x[m_1-(254)]
}
var _UnumValues = []Unum{m0, m1, m2, m_2, m_1}
var _UnumNameToValueMap = map[string]Unum{
_UnumName_0[0:2]: m0,
_UnumLowerName_0[0:2]: m0,
_UnumName_0[2:4]: m1,
_UnumLowerName_0[2:4]: m1,
_UnumName_0[4:6]: m2,
_UnumLowerName_0[4:6]: m2,
_UnumName_1[0:3]: m_2,
_UnumLowerName_1[0:3]: m_2,
_UnumName_1[3:6]: m_1,
_UnumLowerName_1[3:6]: m_1,
}
var _UnumNames = []string{
_UnumName_0[0:2],
_UnumName_0[2:4],
_UnumName_0[4:6],
_UnumName_1[0:3],
_UnumName_1[3:6],
}
// UnumString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func UnumString(s string) (Unum, error) {
if val, ok := _UnumNameToValueMap[s]; ok {
return val, nil
}
s = strings.ToLower(s)
if val, ok := _UnumNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Unum values", s)
}
// UnumValues returns all values of the enum
func UnumValues() []Unum {
return _UnumValues
}
// UnumStrings returns a slice of all String values of the enum
func UnumStrings() []string {
strs := make([]string, len(_UnumNames))
copy(strs, _UnumNames)
return strs
}
// IsAUnum returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Unum) IsAUnum() bool {
for _, v := range _UnumValues {
if i == v {
return true
}
}
return false
}