diff --git a/testdata/day.golden b/testdata/day.golden index f23e69b..a79333d 100644 --- a/testdata/day.golden +++ b/testdata/day.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } func (Day) Values() []string { diff --git a/testdata/dayTrimAndPrefix.golden b/testdata/dayTrimAndPrefix.golden index 7f5367d..3160cab 100644 --- a/testdata/dayTrimAndPrefix.golden +++ b/testdata/dayTrimAndPrefix.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 11, 23, 37, 50, 61, 74, 85} const _DayLowerName = "nightmondaynighttuesdaynightwednesdaynightthursdaynightfridaynightsaturdaynightsunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/dayWithLinecomment.golden b/testdata/dayWithLinecomment.golden index c6b8584..d90b901 100644 --- a/testdata/dayWithLinecomment.golden +++ b/testdata/dayWithLinecomment.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 5, 12, 21, 29, 36, 44, 50} const _DayLowerName = "lunestuesdaywednesdaythursdayviernessaturdaysunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/dayWithPrefix.golden b/testdata/dayWithPrefix.golden index d468741..8dc17fa 100644 --- a/testdata/dayWithPrefix.golden +++ b/testdata/dayWithPrefix.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 9, 19, 31, 42, 51, 62, 71} const _DayLowerName = "daymondaydaytuesdaydaywednesdaydaythursdaydayfridaydaysaturdaydaysunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/gap.golden b/testdata/gap.golden index cc3e48d..6a54c83 100644 --- a/testdata/gap.golden +++ b/testdata/gap.golden @@ -25,7 +25,7 @@ func (i Gap) String() string { case i == 11: return _GapName_2 default: - return fmt.Sprintf("Gap(%d)", i) + return "" } } diff --git a/testdata/num.golden b/testdata/num.golden index 97cc937..47d2ef4 100644 --- a/testdata/num.golden +++ b/testdata/num.golden @@ -5,12 +5,17 @@ var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12} const _NumLowerName = "m_2m_1m0m1m2" -func (i Num) String() string { +func (i Num) string() (string, error) { i -= -2 if i < 0 || i >= Num(len(_NumIndex)-1) { - return fmt.Sprintf("Num(%d)", i+-2) + return "", fmt.Errorf("value is out of enum range") } - return _NumName[_NumIndex[i]:_NumIndex[i+1]] + return _NumName[_NumIndex[i]:_NumIndex[i+1]], nil +} + +func (i Num) String() string { + val, _ := i.string() + return val } func (Num) Values() []string { diff --git a/testdata/offset.golden b/testdata/offset.golden index 0e52817..d7983f2 100644 --- a/testdata/offset.golden +++ b/testdata/offset.golden @@ -5,12 +5,17 @@ var _NumberIndex = [...]uint8{0, 3, 6, 11} const _NumberLowerName = "onetwothree" -func (i Number) String() string { +func (i Number) string() (string, error) { i -= 1 if i < 0 || i >= Number(len(_NumberIndex)-1) { - return fmt.Sprintf("Number(%d)", i+1) + return "", fmt.Errorf("value is out of enum range") } - return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]] + return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]], nil +} + +func (i Number) String() string { + val, _ := i.string() + return val } func (Number) Values() []string { diff --git a/testdata/prime.golden b/testdata/prime.golden index 8783338..3c54e43 100644 --- a/testdata/prime.golden +++ b/testdata/prime.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } func (Prime) Values() []string { diff --git a/testdata/primeGQLGen.golden b/testdata/primeGQLGen.golden index 14c8eff..14822bc 100644 --- a/testdata/primeGQLGen.golden +++ b/testdata/primeGQLGen.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/primeJson.golden b/testdata/primeJson.golden index 9224728..beee577 100644 --- a/testdata/primeJson.golden +++ b/testdata/primeJson.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/primeJsonAndSql.golden b/testdata/primeJsonAndSql.golden index 1133b4a..27b5acb 100644 --- a/testdata/primeJsonAndSql.golden +++ b/testdata/primeJsonAndSql.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. @@ -140,7 +145,7 @@ func (i *Prime) UnmarshalJSON(data []byte) error { } func (i Prime) Value() (driver.Value, error) { - return i.String(), nil + return i.string() } func (i *Prime) Scan(value interface{}) error { diff --git a/testdata/primeSql.golden b/testdata/primeSql.golden index 9a5292a..092fa70 100644 --- a/testdata/primeSql.golden +++ b/testdata/primeSql.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. @@ -123,7 +128,7 @@ func (i Prime) IsAPrime() bool { } func (i Prime) Value() (driver.Value, error) { - return i.String(), nil + return i.string() } func (i *Prime) Scan(value interface{}) error { diff --git a/testdata/primeText.golden b/testdata/primeText.golden index e8102d6..1c4eb64 100644 --- a/testdata/primeText.golden +++ b/testdata/primeText.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/primeYaml.golden b/testdata/primeYaml.golden index 5197219..3b1b24e 100644 --- a/testdata/primeYaml.golden +++ b/testdata/primeYaml.golden @@ -18,11 +18,16 @@ var _PrimeMap = map[Prime]string{ 43: _PrimeName[32:35], } -func (i Prime) String() string { +func (i Prime) string() (string, error) { if str, ok := _PrimeMap[i]; ok { - return str + return str, nil } - return fmt.Sprintf("Prime(%d)", i) + return "", fmt.Errorf("value is out of enum range") +} + +func (i Prime) String() string { + str, _ := i.string() + return str } // An "invalid array index" compiler error signifies that the constant values have changed. @@ -124,7 +129,7 @@ func (i Prime) IsAPrime() bool { // MarshalYAML implements a YAML Marshaler for Prime func (i Prime) MarshalYAML() (interface{}, error) { - return i.String(), nil + return i.string() } // UnmarshalYAML implements a YAML Unmarshaler for Prime diff --git a/testdata/trimPrefix.golden b/testdata/trimPrefix.golden index 52f063e..b919e75 100644 --- a/testdata/trimPrefix.golden +++ b/testdata/trimPrefix.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/trimPrefixMultiple.golden b/testdata/trimPrefixMultiple.golden index 439ca92..1aa2d42 100644 --- a/testdata/trimPrefixMultiple.golden +++ b/testdata/trimPrefixMultiple.golden @@ -5,11 +5,16 @@ var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" -func (i Day) String() string { +func (i Day) string() (string, error) { if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) + return "", fmt.Errorf("value is out of enum range") } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] + return _DayName[_DayIndex[i]:_DayIndex[i+1]], nil +} + +func (i Day) String() string { + val, _ := i.string() + return val } // An "invalid array index" compiler error signifies that the constant values have changed. diff --git a/testdata/unum.golden b/testdata/unum.golden index 9e413dc..d327701 100644 --- a/testdata/unum.golden +++ b/testdata/unum.golden @@ -19,7 +19,7 @@ func (i Unum) String() string { i -= 253 return _UnumName_1[_UnumIndex_1[i]:_UnumIndex_1[i+1]] default: - return fmt.Sprintf("Unum(%d)", i) + return "" } }