From eb484e644077f42eee1ee752bc3cd71ea67bd53e Mon Sep 17 00:00:00 2001 From: Dan Markham Date: Sat, 8 Aug 2020 21:14:17 -0700 Subject: [PATCH] case insensitive bug fix --- endtoend_test.go | 3 +- enumer.go | 4 + golden_test.go | 1787 +--------------------------- stringer.go | 1 + testdata/day.golden | 90 ++ testdata/dayTrimAndPrefix.golden | 90 ++ testdata/dayWithLinecomment.golden | 90 ++ testdata/dayWithPrefix.golden | 90 ++ testdata/gap.golden | 111 ++ testdata/num.golden | 83 ++ testdata/offset.golden | 75 ++ testdata/prime.golden | 123 ++ testdata/primeJson.golden | 140 +++ testdata/primeJsonAndSql.golden | 170 +++ testdata/primeSql.golden | 153 +++ testdata/primeText.golden | 135 +++ testdata/primeYaml.golden | 140 +++ testdata/trimPrefix.golden | 90 ++ testdata/trimPrefixMultiple.golden | 90 ++ testdata/unum.golden | 93 ++ 20 files changed, 1805 insertions(+), 1753 deletions(-) create mode 100644 testdata/day.golden create mode 100644 testdata/dayTrimAndPrefix.golden create mode 100644 testdata/dayWithLinecomment.golden create mode 100644 testdata/dayWithPrefix.golden create mode 100644 testdata/gap.golden create mode 100644 testdata/num.golden create mode 100644 testdata/offset.golden create mode 100644 testdata/prime.golden create mode 100644 testdata/primeJson.golden create mode 100644 testdata/primeJsonAndSql.golden create mode 100644 testdata/primeSql.golden create mode 100644 testdata/primeText.golden create mode 100644 testdata/primeYaml.golden create mode 100644 testdata/trimPrefix.golden create mode 100644 testdata/trimPrefixMultiple.golden create mode 100644 testdata/unum.golden diff --git a/endtoend_test.go b/endtoend_test.go index da9ba60..203ecd6 100644 --- a/endtoend_test.go +++ b/endtoend_test.go @@ -65,7 +65,6 @@ func TestEndToEnd(t *testing.T) { // Generate, compile, and run the test programs. for _, name := range names { if !strings.HasSuffix(name, ".go") { - t.Errorf("%s is not a Go file", name) continue } if name == "cgo.go" && !build.Default.CgoEnabled { @@ -172,4 +171,4 @@ func runInDir(dir, name string, arg ...string) error { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() -} \ No newline at end of file +} diff --git a/enumer.go b/enumer.go index 45ac04e..3cb1f5d 100644 --- a/enumer.go +++ b/enumer.go @@ -7,6 +7,10 @@ import "fmt" const stringNameToValueMethod = `// %[1]sString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. func %[1]sString(s string) (%[1]s, error) { + if val, ok := _%[1]sNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) if val, ok := _%[1]sNameToValueMap[s]; ok { return val, nil } diff --git a/golden_test.go b/golden_test.go index bc90038..f23f424 100644 --- a/golden_test.go +++ b/golden_test.go @@ -19,57 +19,57 @@ import ( // Golden represents a test case. type Golden struct { - name string - input string // input; the package clause is provided when running the test. - output string // expected output. + name string + input string // input; the package clause is provided when running the test. + //output string // expected output. } var golden = []Golden{ - {"day", dayIn, dayOut}, - {"offset", offsetIn, offsetOut}, - {"gap", gapIn, gapOut}, - {"num", numIn, numOut}, - {"unum", unumIn, unumOut}, - {"prime", primeIn, primeOut}, + {"day", dayIn}, + {"offset", offsetIn}, + {"gap", gapIn}, + {"num", numIn}, + {"unum", unumIn}, + {"prime", primeIn}, } var goldenJSON = []Golden{ - {"primeJson", primeJsonIn, primeJsonOut}, + {"primeJson", primeJsonIn}, } var goldenText = []Golden{ - {"primeText", primeTextIn, primeTextOut}, + {"primeText", primeTextIn}, } var goldenYAML = []Golden{ - {"primeYaml", primeYamlIn, primeYamlOut}, + {"primeYaml", primeYamlIn}, } var goldenSQL = []Golden{ - {"primeSql", primeSqlIn, primeSqlOut}, + {"primeSql", primeSqlIn}, } var goldenJSONAndSQL = []Golden{ - {"primeJsonAndSql", primeJsonAndSqlIn, primeJsonAndSqlOut}, + {"primeJsonAndSql", primeJsonAndSqlIn}, } var goldenTrimPrefix = []Golden{ - {"trimPrefix", trimPrefixIn, trimPrefixOut}, + {"trimPrefix", trimPrefixIn}, } var goldenTrimPrefixMultiple = []Golden{ - {"trimPrefixMultiple", trimPrefixMultipleIn, dayNightOut}, + {"trimPrefixMultiple", trimPrefixMultipleIn}, } var goldenWithPrefix = []Golden{ - {"dayWithPrefix", dayIn, prefixedDayOut}, + {"dayWithPrefix", dayIn}, } var goldenTrimAndAddPrefix = []Golden{ - {"dayTrimAndPrefix", trimPrefixIn, trimmedPrefixedDayOut}, + {"dayTrimAndPrefix", trimPrefixIn}, } var goldenLinecomment = []Golden{ - {"dayWithLinecomment", linecommentIn, linecommentOut}, + {"dayWithLinecomment", linecommentIn}, } // Each example starts with "type XXX [u]int", with a single space separating them. @@ -86,445 +86,6 @@ const ( Sunday ) ` -const trimPrefixOut = ` -const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" - -var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} - -const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[DayMonday-(0)] - _ = x[DayTuesday-(1)] - _ = x[DayWednesday-(2)] - _ = x[DayThursday-(3)] - _ = x[DayFriday-(4)] - _ = x[DaySaturday-(5)] - _ = x[DaySunday-(6)] -} - -var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:6]: DayMonday, - _DayLowerName[0:6]: DayMonday, - _DayName[6:13]: DayTuesday, - _DayLowerName[6:13]: DayTuesday, - _DayName[13:22]: DayWednesday, - _DayLowerName[13:22]: DayWednesday, - _DayName[22:30]: DayThursday, - _DayLowerName[22:30]: DayThursday, - _DayName[30:36]: DayFriday, - _DayLowerName[30:36]: DayFriday, - _DayName[36:44]: DaySaturday, - _DayLowerName[36:44]: DaySaturday, - _DayName[44:50]: DaySunday, - _DayLowerName[44:50]: DaySunday, -} - -var _DayNames = []string{ - _DayName[0:6], - _DayName[6:13], - _DayName[13:22], - _DayName[22:30], - _DayName[30:36], - _DayName[36:44], - _DayName[44:50], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` - -const dayOut = ` -const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" - -var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} - -const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[Monday-(0)] - _ = x[Tuesday-(1)] - _ = x[Wednesday-(2)] - _ = x[Thursday-(3)] - _ = x[Friday-(4)] - _ = x[Saturday-(5)] - _ = x[Sunday-(6)] -} - -var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:6]: Monday, - _DayLowerName[0:6]: Monday, - _DayName[6:13]: Tuesday, - _DayLowerName[6:13]: Tuesday, - _DayName[13:22]: Wednesday, - _DayLowerName[13:22]: Wednesday, - _DayName[22:30]: Thursday, - _DayLowerName[22:30]: Thursday, - _DayName[30:36]: Friday, - _DayLowerName[30:36]: Friday, - _DayName[36:44]: Saturday, - _DayLowerName[36:44]: Saturday, - _DayName[44:50]: Sunday, - _DayLowerName[44:50]: Sunday, -} - -var _DayNames = []string{ - _DayName[0:6], - _DayName[6:13], - _DayName[13:22], - _DayName[22:30], - _DayName[30:36], - _DayName[36:44], - _DayName[44:50], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` - -const dayNightOut = ` -const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" - -var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} - -const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[DayMonday-(0)] - _ = x[NightTuesday-(1)] - _ = x[DayWednesday-(2)] - _ = x[NightThursday-(3)] - _ = x[DayFriday-(4)] - _ = x[NightSaturday-(5)] - _ = x[DaySunday-(6)] -} - -var _DayValues = []Day{DayMonday, NightTuesday, DayWednesday, NightThursday, DayFriday, NightSaturday, DaySunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:6]: DayMonday, - _DayLowerName[0:6]: DayMonday, - _DayName[6:13]: NightTuesday, - _DayLowerName[6:13]: NightTuesday, - _DayName[13:22]: DayWednesday, - _DayLowerName[13:22]: DayWednesday, - _DayName[22:30]: NightThursday, - _DayLowerName[22:30]: NightThursday, - _DayName[30:36]: DayFriday, - _DayLowerName[30:36]: DayFriday, - _DayName[36:44]: NightSaturday, - _DayLowerName[36:44]: NightSaturday, - _DayName[44:50]: DaySunday, - _DayLowerName[44:50]: DaySunday, -} - -var _DayNames = []string{ - _DayName[0:6], - _DayName[6:13], - _DayName[13:22], - _DayName[22:30], - _DayName[30:36], - _DayName[36:44], - _DayName[44:50], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` - -const prefixedDayOut = ` -const _DayName = "DayMondayDayTuesdayDayWednesdayDayThursdayDayFridayDaySaturdayDaySunday" - -var _DayIndex = [...]uint8{0, 9, 19, 31, 42, 51, 62, 71} - -const _DayLowerName = "daymondaydaytuesdaydaywednesdaydaythursdaydayfridaydaysaturdaydaysunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[Monday-(0)] - _ = x[Tuesday-(1)] - _ = x[Wednesday-(2)] - _ = x[Thursday-(3)] - _ = x[Friday-(4)] - _ = x[Saturday-(5)] - _ = x[Sunday-(6)] -} - -var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:9]: Monday, - _DayLowerName[0:9]: Monday, - _DayName[9:19]: Tuesday, - _DayLowerName[9:19]: Tuesday, - _DayName[19:31]: Wednesday, - _DayLowerName[19:31]: Wednesday, - _DayName[31:42]: Thursday, - _DayLowerName[31:42]: Thursday, - _DayName[42:51]: Friday, - _DayLowerName[42:51]: Friday, - _DayName[51:62]: Saturday, - _DayLowerName[51:62]: Saturday, - _DayName[62:71]: Sunday, - _DayLowerName[62:71]: Sunday, -} - -var _DayNames = []string{ - _DayName[0:9], - _DayName[9:19], - _DayName[19:31], - _DayName[31:42], - _DayName[42:51], - _DayName[51:62], - _DayName[62:71], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` - -const trimmedPrefixedDayOut = ` -const _DayName = "NightMondayNightTuesdayNightWednesdayNightThursdayNightFridayNightSaturdayNightSunday" - -var _DayIndex = [...]uint8{0, 11, 23, 37, 50, 61, 74, 85} - -const _DayLowerName = "nightmondaynighttuesdaynightwednesdaynightthursdaynightfridaynightsaturdaynightsunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[DayMonday-(0)] - _ = x[DayTuesday-(1)] - _ = x[DayWednesday-(2)] - _ = x[DayThursday-(3)] - _ = x[DayFriday-(4)] - _ = x[DaySaturday-(5)] - _ = x[DaySunday-(6)] -} - -var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:11]: DayMonday, - _DayLowerName[0:11]: DayMonday, - _DayName[11:23]: DayTuesday, - _DayLowerName[11:23]: DayTuesday, - _DayName[23:37]: DayWednesday, - _DayLowerName[23:37]: DayWednesday, - _DayName[37:50]: DayThursday, - _DayLowerName[37:50]: DayThursday, - _DayName[50:61]: DayFriday, - _DayLowerName[50:61]: DayFriday, - _DayName[61:74]: DaySaturday, - _DayLowerName[61:74]: DaySaturday, - _DayName[74:85]: DaySunday, - _DayLowerName[74:85]: DaySunday, -} - -var _DayNames = []string{ - _DayName[0:11], - _DayName[11:23], - _DayName[23:37], - _DayName[37:50], - _DayName[50:61], - _DayName[61:74], - _DayName[74:85], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` // Enumeration with an offset. // Also includes a duplicate. @@ -538,79 +99,6 @@ const ( ) ` -const offsetOut = ` -const _NumberName = "OneTwoThree" - -var _NumberIndex = [...]uint8{0, 3, 6, 11} - -const _NumberLowerName = "onetwothree" - -func (i Number) String() string { - i -= 1 - if i < 0 || i >= Number(len(_NumberIndex)-1) { - return fmt.Sprintf("Number(%d)", i+1) - } - return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _NumberNoOp() { - var x [1]struct{} - _ = x[One-(1)] - _ = x[Two-(2)] - _ = x[Three-(3)] -} - -var _NumberValues = []Number{One, Two, Three} - -var _NumberNameToValueMap = map[string]Number{ - _NumberName[0:3]: One, - _NumberLowerName[0:3]: One, - _NumberName[3:6]: Two, - _NumberLowerName[3:6]: Two, - _NumberName[6:11]: Three, - _NumberLowerName[6:11]: Three, -} - -var _NumberNames = []string{ - _NumberName[0:3], - _NumberName[3:6], - _NumberName[6:11], -} - -// NumberString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func NumberString(s string) (Number, error) { - if val, ok := _NumberNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Number values", s) -} - -// NumberValues returns all values of the enum -func NumberValues() []Number { - return _NumberValues -} - -// NumberStrings returns a slice of all String values of the enum -func NumberStrings() []string { - strs := make([]string, len(_NumberNames)) - copy(strs, _NumberNames) - return strs -} - -// IsANumber returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Number) IsANumber() bool { - for _, v := range _NumberValues { - if i == v { - return true - } - } - return false -} -` - // Gaps and an offset. const gapIn = `type Gap int const ( @@ -625,115 +113,6 @@ const ( ) ` -const gapOut = ` -const ( - _GapName_0 = "TwoThree" - _GapLowerName_0 = "twothree" - _GapName_1 = "FiveSixSevenEightNine" - _GapLowerName_1 = "fivesixseveneightnine" - _GapName_2 = "Eleven" - _GapLowerName_2 = "eleven" -) - -var ( - _GapIndex_0 = [...]uint8{0, 3, 8} - _GapIndex_1 = [...]uint8{0, 4, 7, 12, 17, 21} - _GapIndex_2 = [...]uint8{0, 6} -) - -func (i Gap) String() string { - switch { - case 2 <= i && i <= 3: - i -= 2 - return _GapName_0[_GapIndex_0[i]:_GapIndex_0[i+1]] - case 5 <= i && i <= 9: - i -= 5 - return _GapName_1[_GapIndex_1[i]:_GapIndex_1[i+1]] - case i == 11: - return _GapName_2 - default: - return fmt.Sprintf("Gap(%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 _GapNoOp() { - var x [1]struct{} - _ = x[Two-(2)] - _ = x[Three-(3)] - _ = x[Five-(5)] - _ = x[Six-(6)] - _ = x[Seven-(7)] - _ = x[Eight-(8)] - _ = x[Nine-(9)] - _ = x[Eleven-(11)] -} - -var _GapValues = []Gap{Two, Three, Five, Six, Seven, Eight, Nine, Eleven} - -var _GapNameToValueMap = map[string]Gap{ - _GapName_0[0:3]: Two, - _GapLowerName_0[0:3]: Two, - _GapName_0[3:8]: Three, - _GapLowerName_0[3:8]: Three, - _GapName_1[0:4]: Five, - _GapLowerName_1[0:4]: Five, - _GapName_1[4:7]: Six, - _GapLowerName_1[4:7]: Six, - _GapName_1[7:12]: Seven, - _GapLowerName_1[7:12]: Seven, - _GapName_1[12:17]: Eight, - _GapLowerName_1[12:17]: Eight, - _GapName_1[17:21]: Nine, - _GapLowerName_1[17:21]: Nine, - _GapName_2[0:6]: Eleven, - _GapLowerName_2[0:6]: Eleven, -} - -var _GapNames = []string{ - _GapName_0[0:3], - _GapName_0[3:8], - _GapName_1[0:4], - _GapName_1[4:7], - _GapName_1[7:12], - _GapName_1[12:17], - _GapName_1[17:21], - _GapName_2[0:6], -} - -// GapString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func GapString(s string) (Gap, error) { - if val, ok := _GapNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Gap values", s) -} - -// GapValues returns all values of the enum -func GapValues() []Gap { - return _GapValues -} - -// GapStrings returns a slice of all String values of the enum -func GapStrings() []string { - strs := make([]string, len(_GapNames)) - copy(strs, _GapNames) - return strs -} - -// IsAGap returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Gap) IsAGap() bool { - for _, v := range _GapValues { - if i == v { - return true - } - } - return false -} -` - // Signed integers spanning zero. const numIn = `type Num int const ( @@ -745,87 +124,6 @@ const ( ) ` -const numOut = ` -const _NumName = "m_2m_1m0m1m2" - -var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12} - -const _NumLowerName = "m_2m_1m0m1m2" - -func (i Num) String() string { - i -= -2 - if i < 0 || i >= Num(len(_NumIndex)-1) { - return fmt.Sprintf("Num(%d)", i+-2) - } - return _NumName[_NumIndex[i]:_NumIndex[i+1]] -} - -// 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 - } - 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 -} -` - // Unsigned integers spanning zero. const unumIn = `type Unum uint const ( @@ -840,97 +138,6 @@ const ( ) ` -const unumOut = ` -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 - } - 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 -} -` - // Enough gaps to trigger a map implementation of the method. // Also includes a duplicate to test that it doesn't cause problems const primeIn = `type Prime int @@ -952,126 +159,6 @@ const ( ) ` -const primeOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} -` const primeJsonIn = `type Prime int const ( p2 Prime = 2 @@ -1091,144 +178,6 @@ const ( ) ` -const primeJsonOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} - -// MarshalJSON implements the json.Marshaler interface for Prime -func (i Prime) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -// UnmarshalJSON implements the json.Unmarshaler interface for Prime -func (i *Prime) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return fmt.Errorf("Prime should be a string, got %s", data) - } - - var err error - *i, err = PrimeString(s) - return err -} -` - const primeTextIn = `type Prime int const ( p2 Prime = 2 @@ -1248,139 +197,6 @@ const ( ) ` -const primeTextOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} - -// MarshalText implements the encoding.TextMarshaler interface for Prime -func (i Prime) MarshalText() ([]byte, error) { - return []byte(i.String()), nil -} - -// UnmarshalText implements the encoding.TextUnmarshaler interface for Prime -func (i *Prime) UnmarshalText(text []byte) error { - var err error - *i, err = PrimeString(string(text)) - return err -} -` - const primeYamlIn = `type Prime int const ( p2 Prime = 2 @@ -1400,144 +216,6 @@ const ( ) ` -const primeYamlOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} - -// MarshalYAML implements a YAML Marshaler for Prime -func (i Prime) MarshalYAML() (interface{}, error) { - return i.String(), nil -} - -// UnmarshalYAML implements a YAML Unmarshaler for Prime -func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error { - var s string - if err := unmarshal(&s); err != nil { - return err - } - - var err error - *i, err = PrimeString(s) - return err -} -` - const primeSqlIn = `type Prime int const ( p2 Prime = 2 @@ -1557,157 +235,6 @@ const ( ) ` -const primeSqlOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} - -func (i Prime) Value() (driver.Value, error) { - return i.String(), nil -} - -func (i *Prime) Scan(value interface{}) error { - if value == nil { - return nil - } - - var str string - switch v := value.(type) { - case []byte: - str = string(v) - case string: - str = v - case fmt.Stringer: - str = v.String() - default: - return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value) - } - - val, err := PrimeString(str) - if err != nil { - return err - } - - *i = val - return nil -} -` - const primeJsonAndSqlIn = `type Prime int const ( p2 Prime = 2 @@ -1727,174 +254,6 @@ const ( ) ` -const primeJsonAndSqlOut = ` -const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" -const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" - -var _PrimeMap = map[Prime]string{ - 2: _PrimeName[0:2], - 3: _PrimeName[2:4], - 5: _PrimeName[4:6], - 7: _PrimeName[6:8], - 11: _PrimeName[8:11], - 13: _PrimeName[11:14], - 17: _PrimeName[14:17], - 19: _PrimeName[17:20], - 23: _PrimeName[20:23], - 29: _PrimeName[23:26], - 31: _PrimeName[26:29], - 41: _PrimeName[29:32], - 43: _PrimeName[32:35], -} - -func (i Prime) String() string { - if str, ok := _PrimeMap[i]; ok { - return str - } - return fmt.Sprintf("Prime(%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 _PrimeNoOp() { - var x [1]struct{} - _ = x[p2-(2)] - _ = x[p3-(3)] - _ = x[p5-(5)] - _ = x[p7-(7)] - _ = x[p11-(11)] - _ = x[p13-(13)] - _ = x[p17-(17)] - _ = x[p19-(19)] - _ = x[p23-(23)] - _ = x[p29-(29)] - _ = x[p37-(31)] - _ = x[p41-(41)] - _ = x[p43-(43)] -} - -var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} - -var _PrimeNameToValueMap = map[string]Prime{ - _PrimeName[0:2]: p2, - _PrimeLowerName[0:2]: p2, - _PrimeName[2:4]: p3, - _PrimeLowerName[2:4]: p3, - _PrimeName[4:6]: p5, - _PrimeLowerName[4:6]: p5, - _PrimeName[6:8]: p7, - _PrimeLowerName[6:8]: p7, - _PrimeName[8:11]: p11, - _PrimeLowerName[8:11]: p11, - _PrimeName[11:14]: p13, - _PrimeLowerName[11:14]: p13, - _PrimeName[14:17]: p17, - _PrimeLowerName[14:17]: p17, - _PrimeName[17:20]: p19, - _PrimeLowerName[17:20]: p19, - _PrimeName[20:23]: p23, - _PrimeLowerName[20:23]: p23, - _PrimeName[23:26]: p29, - _PrimeLowerName[23:26]: p29, - _PrimeName[26:29]: p37, - _PrimeLowerName[26:29]: p37, - _PrimeName[29:32]: p41, - _PrimeLowerName[29:32]: p41, - _PrimeName[32:35]: p43, - _PrimeLowerName[32:35]: p43, -} - -var _PrimeNames = []string{ - _PrimeName[0:2], - _PrimeName[2:4], - _PrimeName[4:6], - _PrimeName[6:8], - _PrimeName[8:11], - _PrimeName[11:14], - _PrimeName[14:17], - _PrimeName[17:20], - _PrimeName[20:23], - _PrimeName[23:26], - _PrimeName[26:29], - _PrimeName[29:32], - _PrimeName[32:35], -} - -// PrimeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PrimeString(s string) (Prime, error) { - if val, ok := _PrimeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Prime values", s) -} - -// PrimeValues returns all values of the enum -func PrimeValues() []Prime { - return _PrimeValues -} - -// PrimeStrings returns a slice of all String values of the enum -func PrimeStrings() []string { - strs := make([]string, len(_PrimeNames)) - copy(strs, _PrimeNames) - return strs -} - -// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Prime) IsAPrime() bool { - _, ok := _PrimeMap[i] - return ok -} - -// MarshalJSON implements the json.Marshaler interface for Prime -func (i Prime) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -// UnmarshalJSON implements the json.Unmarshaler interface for Prime -func (i *Prime) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return fmt.Errorf("Prime should be a string, got %s", data) - } - - var err error - *i, err = PrimeString(s) - return err -} - -func (i Prime) Value() (driver.Value, error) { - return i.String(), nil -} - -func (i *Prime) Scan(value interface{}) error { - if value == nil { - return nil - } - - var str string - switch v := value.(type) { - case []byte: - str = string(v) - case string: - str = v - case fmt.Stringer: - str = v.String() - default: - return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value) - } - - val, err := PrimeString(str) - if err != nil { - return err - } - - *i = val - return nil -} -` - const trimPrefixIn = `type Day int const ( DayMonday Day = iota @@ -1931,94 +290,6 @@ const ( ) ` -const linecommentOut = ` -const _DayName = "lunesTuesdayWednesdayThursdayviernesSaturdaySunday" - -var _DayIndex = [...]uint8{0, 5, 12, 21, 29, 36, 44, 50} - -const _DayLowerName = "lunestuesdaywednesdaythursdayviernessaturdaysunday" - -func (i Day) String() string { - if i < 0 || i >= Day(len(_DayIndex)-1) { - return fmt.Sprintf("Day(%d)", i) - } - return _DayName[_DayIndex[i]:_DayIndex[i+1]] -} - -// An "invalid array index" compiler error signifies that the constant values have changed. -// Re-run the stringer command to generate them again. -func _DayNoOp() { - var x [1]struct{} - _ = x[Monday-(0)] - _ = x[Tuesday-(1)] - _ = x[Wednesday-(2)] - _ = x[Thursday-(3)] - _ = x[Friday-(4)] - _ = x[Saturday-(5)] - _ = x[Sunday-(6)] -} - -var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} - -var _DayNameToValueMap = map[string]Day{ - _DayName[0:5]: Monday, - _DayLowerName[0:5]: Monday, - _DayName[5:12]: Tuesday, - _DayLowerName[5:12]: Tuesday, - _DayName[12:21]: Wednesday, - _DayLowerName[12:21]: Wednesday, - _DayName[21:29]: Thursday, - _DayLowerName[21:29]: Thursday, - _DayName[29:36]: Friday, - _DayLowerName[29:36]: Friday, - _DayName[36:44]: Saturday, - _DayLowerName[36:44]: Saturday, - _DayName[44:50]: Sunday, - _DayLowerName[44:50]: Sunday, -} - -var _DayNames = []string{ - _DayName[0:5], - _DayName[5:12], - _DayName[12:21], - _DayName[21:29], - _DayName[29:36], - _DayName[36:44], - _DayName[44:50], -} - -// DayString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func DayString(s string) (Day, error) { - if val, ok := _DayNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to Day values", s) -} - -// DayValues returns all values of the enum -func DayValues() []Day { - return _DayValues -} - -// DayStrings returns a slice of all String values of the enum -func DayStrings() []string { - strs := make([]string, len(_DayNames)) - copy(strs, _DayNames) - return strs -} - -// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise -func (i Day) IsADay() bool { - for _, v := range _DayValues { - if i == v { - return true - } - } - return false -} -` - func TestGolden(t *testing.T) { for _, test := range golden { runGoldenTest(t, test, false, false, false, false, false, "", "") @@ -2084,13 +355,27 @@ func runGoldenTest(t *testing.T, test Golden, generateJSON, generateYAML, genera } g.generate(tokens[1], generateJSON, generateYAML, generateSQL, generateText, "noop", trimPrefix, prefix, linecomment) got := string(g.format()) - if got != test.output { + if got != loadGolden(test.name) { // Use this to help build a golden text when changes are needed - //goldenFile := fmt.Sprintf("./goldendata/%v.golden", test.name) + //goldenFile := fmt.Sprintf("./testdata/%v.golden", test.name) //err = ioutil.WriteFile(goldenFile, []byte(got), 0644) //if err != nil { // t.Error(err) //} - t.Errorf("%s: got\n====\n%s====\nexpected\n====%s", test.name, got, test.output) + t.Errorf("%s: got\n====\n%s====\nexpected\n====%s", test.name, got, loadGolden(test.name)) } } + +func loadGolden(name string) string { + fh, err := os.Open("testdata/" + name + ".golden") + if err != nil { + return "" + } + defer fh.Close() + b, err := ioutil.ReadAll(fh) + if err != nil { + return "" + } + return string(b) + +} diff --git a/stringer.go b/stringer.go index 594e2f3..0159f04 100644 --- a/stringer.go +++ b/stringer.go @@ -118,6 +118,7 @@ func main() { g.Printf("\n") g.Printf("import (\n") g.Printf("\t\"fmt\"\n") + g.Printf("\t\"strings\"\n") if *sql { g.Printf("\t\"database/sql/driver\"\n") } diff --git a/testdata/day.golden b/testdata/day.golden new file mode 100644 index 0000000..fd4a481 --- /dev/null +++ b/testdata/day.golden @@ -0,0 +1,90 @@ + +const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" + +var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} + +const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[Monday-(0)] + _ = x[Tuesday-(1)] + _ = x[Wednesday-(2)] + _ = x[Thursday-(3)] + _ = x[Friday-(4)] + _ = x[Saturday-(5)] + _ = x[Sunday-(6)] +} + +var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:6]: Monday, + _DayLowerName[0:6]: Monday, + _DayName[6:13]: Tuesday, + _DayLowerName[6:13]: Tuesday, + _DayName[13:22]: Wednesday, + _DayLowerName[13:22]: Wednesday, + _DayName[22:30]: Thursday, + _DayLowerName[22:30]: Thursday, + _DayName[30:36]: Friday, + _DayLowerName[30:36]: Friday, + _DayName[36:44]: Saturday, + _DayLowerName[36:44]: Saturday, + _DayName[44:50]: Sunday, + _DayLowerName[44:50]: Sunday, +} + +var _DayNames = []string{ + _DayName[0:6], + _DayName[6:13], + _DayName[13:22], + _DayName[22:30], + _DayName[30:36], + _DayName[36:44], + _DayName[44:50], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/dayTrimAndPrefix.golden b/testdata/dayTrimAndPrefix.golden new file mode 100644 index 0000000..c3afe9e --- /dev/null +++ b/testdata/dayTrimAndPrefix.golden @@ -0,0 +1,90 @@ + +const _DayName = "NightMondayNightTuesdayNightWednesdayNightThursdayNightFridayNightSaturdayNightSunday" + +var _DayIndex = [...]uint8{0, 11, 23, 37, 50, 61, 74, 85} + +const _DayLowerName = "nightmondaynighttuesdaynightwednesdaynightthursdaynightfridaynightsaturdaynightsunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[DayMonday-(0)] + _ = x[DayTuesday-(1)] + _ = x[DayWednesday-(2)] + _ = x[DayThursday-(3)] + _ = x[DayFriday-(4)] + _ = x[DaySaturday-(5)] + _ = x[DaySunday-(6)] +} + +var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:11]: DayMonday, + _DayLowerName[0:11]: DayMonday, + _DayName[11:23]: DayTuesday, + _DayLowerName[11:23]: DayTuesday, + _DayName[23:37]: DayWednesday, + _DayLowerName[23:37]: DayWednesday, + _DayName[37:50]: DayThursday, + _DayLowerName[37:50]: DayThursday, + _DayName[50:61]: DayFriday, + _DayLowerName[50:61]: DayFriday, + _DayName[61:74]: DaySaturday, + _DayLowerName[61:74]: DaySaturday, + _DayName[74:85]: DaySunday, + _DayLowerName[74:85]: DaySunday, +} + +var _DayNames = []string{ + _DayName[0:11], + _DayName[11:23], + _DayName[23:37], + _DayName[37:50], + _DayName[50:61], + _DayName[61:74], + _DayName[74:85], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/dayWithLinecomment.golden b/testdata/dayWithLinecomment.golden new file mode 100644 index 0000000..6b5dfdb --- /dev/null +++ b/testdata/dayWithLinecomment.golden @@ -0,0 +1,90 @@ + +const _DayName = "lunesTuesdayWednesdayThursdayviernesSaturdaySunday" + +var _DayIndex = [...]uint8{0, 5, 12, 21, 29, 36, 44, 50} + +const _DayLowerName = "lunestuesdaywednesdaythursdayviernessaturdaysunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[Monday-(0)] + _ = x[Tuesday-(1)] + _ = x[Wednesday-(2)] + _ = x[Thursday-(3)] + _ = x[Friday-(4)] + _ = x[Saturday-(5)] + _ = x[Sunday-(6)] +} + +var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:5]: Monday, + _DayLowerName[0:5]: Monday, + _DayName[5:12]: Tuesday, + _DayLowerName[5:12]: Tuesday, + _DayName[12:21]: Wednesday, + _DayLowerName[12:21]: Wednesday, + _DayName[21:29]: Thursday, + _DayLowerName[21:29]: Thursday, + _DayName[29:36]: Friday, + _DayLowerName[29:36]: Friday, + _DayName[36:44]: Saturday, + _DayLowerName[36:44]: Saturday, + _DayName[44:50]: Sunday, + _DayLowerName[44:50]: Sunday, +} + +var _DayNames = []string{ + _DayName[0:5], + _DayName[5:12], + _DayName[12:21], + _DayName[21:29], + _DayName[29:36], + _DayName[36:44], + _DayName[44:50], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/dayWithPrefix.golden b/testdata/dayWithPrefix.golden new file mode 100644 index 0000000..03a9280 --- /dev/null +++ b/testdata/dayWithPrefix.golden @@ -0,0 +1,90 @@ + +const _DayName = "DayMondayDayTuesdayDayWednesdayDayThursdayDayFridayDaySaturdayDaySunday" + +var _DayIndex = [...]uint8{0, 9, 19, 31, 42, 51, 62, 71} + +const _DayLowerName = "daymondaydaytuesdaydaywednesdaydaythursdaydayfridaydaysaturdaydaysunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[Monday-(0)] + _ = x[Tuesday-(1)] + _ = x[Wednesday-(2)] + _ = x[Thursday-(3)] + _ = x[Friday-(4)] + _ = x[Saturday-(5)] + _ = x[Sunday-(6)] +} + +var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:9]: Monday, + _DayLowerName[0:9]: Monday, + _DayName[9:19]: Tuesday, + _DayLowerName[9:19]: Tuesday, + _DayName[19:31]: Wednesday, + _DayLowerName[19:31]: Wednesday, + _DayName[31:42]: Thursday, + _DayLowerName[31:42]: Thursday, + _DayName[42:51]: Friday, + _DayLowerName[42:51]: Friday, + _DayName[51:62]: Saturday, + _DayLowerName[51:62]: Saturday, + _DayName[62:71]: Sunday, + _DayLowerName[62:71]: Sunday, +} + +var _DayNames = []string{ + _DayName[0:9], + _DayName[9:19], + _DayName[19:31], + _DayName[31:42], + _DayName[42:51], + _DayName[51:62], + _DayName[62:71], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/gap.golden b/testdata/gap.golden new file mode 100644 index 0000000..6561679 --- /dev/null +++ b/testdata/gap.golden @@ -0,0 +1,111 @@ + +const ( + _GapName_0 = "TwoThree" + _GapLowerName_0 = "twothree" + _GapName_1 = "FiveSixSevenEightNine" + _GapLowerName_1 = "fivesixseveneightnine" + _GapName_2 = "Eleven" + _GapLowerName_2 = "eleven" +) + +var ( + _GapIndex_0 = [...]uint8{0, 3, 8} + _GapIndex_1 = [...]uint8{0, 4, 7, 12, 17, 21} + _GapIndex_2 = [...]uint8{0, 6} +) + +func (i Gap) String() string { + switch { + case 2 <= i && i <= 3: + i -= 2 + return _GapName_0[_GapIndex_0[i]:_GapIndex_0[i+1]] + case 5 <= i && i <= 9: + i -= 5 + return _GapName_1[_GapIndex_1[i]:_GapIndex_1[i+1]] + case i == 11: + return _GapName_2 + default: + return fmt.Sprintf("Gap(%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 _GapNoOp() { + var x [1]struct{} + _ = x[Two-(2)] + _ = x[Three-(3)] + _ = x[Five-(5)] + _ = x[Six-(6)] + _ = x[Seven-(7)] + _ = x[Eight-(8)] + _ = x[Nine-(9)] + _ = x[Eleven-(11)] +} + +var _GapValues = []Gap{Two, Three, Five, Six, Seven, Eight, Nine, Eleven} + +var _GapNameToValueMap = map[string]Gap{ + _GapName_0[0:3]: Two, + _GapLowerName_0[0:3]: Two, + _GapName_0[3:8]: Three, + _GapLowerName_0[3:8]: Three, + _GapName_1[0:4]: Five, + _GapLowerName_1[0:4]: Five, + _GapName_1[4:7]: Six, + _GapLowerName_1[4:7]: Six, + _GapName_1[7:12]: Seven, + _GapLowerName_1[7:12]: Seven, + _GapName_1[12:17]: Eight, + _GapLowerName_1[12:17]: Eight, + _GapName_1[17:21]: Nine, + _GapLowerName_1[17:21]: Nine, + _GapName_2[0:6]: Eleven, + _GapLowerName_2[0:6]: Eleven, +} + +var _GapNames = []string{ + _GapName_0[0:3], + _GapName_0[3:8], + _GapName_1[0:4], + _GapName_1[4:7], + _GapName_1[7:12], + _GapName_1[12:17], + _GapName_1[17:21], + _GapName_2[0:6], +} + +// GapString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func GapString(s string) (Gap, error) { + if val, ok := _GapNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _GapNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Gap values", s) +} + +// GapValues returns all values of the enum +func GapValues() []Gap { + return _GapValues +} + +// GapStrings returns a slice of all String values of the enum +func GapStrings() []string { + strs := make([]string, len(_GapNames)) + copy(strs, _GapNames) + return strs +} + +// IsAGap returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Gap) IsAGap() bool { + for _, v := range _GapValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/num.golden b/testdata/num.golden new file mode 100644 index 0000000..f496953 --- /dev/null +++ b/testdata/num.golden @@ -0,0 +1,83 @@ + +const _NumName = "m_2m_1m0m1m2" + +var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12} + +const _NumLowerName = "m_2m_1m0m1m2" + +func (i Num) String() string { + i -= -2 + if i < 0 || i >= Num(len(_NumIndex)-1) { + return fmt.Sprintf("Num(%d)", i+-2) + } + return _NumName[_NumIndex[i]:_NumIndex[i+1]] +} + +// 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 + } + s = strings.ToLower(s) + if val, ok := _NumNameToValueMap[s]; ok { + 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 +} diff --git a/testdata/offset.golden b/testdata/offset.golden new file mode 100644 index 0000000..69e91a9 --- /dev/null +++ b/testdata/offset.golden @@ -0,0 +1,75 @@ + +const _NumberName = "OneTwoThree" + +var _NumberIndex = [...]uint8{0, 3, 6, 11} + +const _NumberLowerName = "onetwothree" + +func (i Number) String() string { + i -= 1 + if i < 0 || i >= Number(len(_NumberIndex)-1) { + return fmt.Sprintf("Number(%d)", i+1) + } + return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _NumberNoOp() { + var x [1]struct{} + _ = x[One-(1)] + _ = x[Two-(2)] + _ = x[Three-(3)] +} + +var _NumberValues = []Number{One, Two, Three} + +var _NumberNameToValueMap = map[string]Number{ + _NumberName[0:3]: One, + _NumberLowerName[0:3]: One, + _NumberName[3:6]: Two, + _NumberLowerName[3:6]: Two, + _NumberName[6:11]: Three, + _NumberLowerName[6:11]: Three, +} + +var _NumberNames = []string{ + _NumberName[0:3], + _NumberName[3:6], + _NumberName[6:11], +} + +// NumberString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func NumberString(s string) (Number, error) { + if val, ok := _NumberNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _NumberNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Number values", s) +} + +// NumberValues returns all values of the enum +func NumberValues() []Number { + return _NumberValues +} + +// NumberStrings returns a slice of all String values of the enum +func NumberStrings() []string { + strs := make([]string, len(_NumberNames)) + copy(strs, _NumberNames) + return strs +} + +// IsANumber returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Number) IsANumber() bool { + for _, v := range _NumberValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/prime.golden b/testdata/prime.golden new file mode 100644 index 0000000..1719eac --- /dev/null +++ b/testdata/prime.golden @@ -0,0 +1,123 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} diff --git a/testdata/primeJson.golden b/testdata/primeJson.golden new file mode 100644 index 0000000..8b1e82f --- /dev/null +++ b/testdata/primeJson.golden @@ -0,0 +1,140 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} + +// MarshalJSON implements the json.Marshaler interface for Prime +func (i Prime) MarshalJSON() ([]byte, error) { + return json.Marshal(i.String()) +} + +// UnmarshalJSON implements the json.Unmarshaler interface for Prime +func (i *Prime) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return fmt.Errorf("Prime should be a string, got %s", data) + } + + var err error + *i, err = PrimeString(s) + return err +} diff --git a/testdata/primeJsonAndSql.golden b/testdata/primeJsonAndSql.golden new file mode 100644 index 0000000..8449e6a --- /dev/null +++ b/testdata/primeJsonAndSql.golden @@ -0,0 +1,170 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} + +// MarshalJSON implements the json.Marshaler interface for Prime +func (i Prime) MarshalJSON() ([]byte, error) { + return json.Marshal(i.String()) +} + +// UnmarshalJSON implements the json.Unmarshaler interface for Prime +func (i *Prime) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return fmt.Errorf("Prime should be a string, got %s", data) + } + + var err error + *i, err = PrimeString(s) + return err +} + +func (i Prime) Value() (driver.Value, error) { + return i.String(), nil +} + +func (i *Prime) Scan(value interface{}) error { + if value == nil { + return nil + } + + var str string + switch v := value.(type) { + case []byte: + str = string(v) + case string: + str = v + case fmt.Stringer: + str = v.String() + default: + return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value) + } + + val, err := PrimeString(str) + if err != nil { + return err + } + + *i = val + return nil +} diff --git a/testdata/primeSql.golden b/testdata/primeSql.golden new file mode 100644 index 0000000..d12a764 --- /dev/null +++ b/testdata/primeSql.golden @@ -0,0 +1,153 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} + +func (i Prime) Value() (driver.Value, error) { + return i.String(), nil +} + +func (i *Prime) Scan(value interface{}) error { + if value == nil { + return nil + } + + var str string + switch v := value.(type) { + case []byte: + str = string(v) + case string: + str = v + case fmt.Stringer: + str = v.String() + default: + return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value) + } + + val, err := PrimeString(str) + if err != nil { + return err + } + + *i = val + return nil +} diff --git a/testdata/primeText.golden b/testdata/primeText.golden new file mode 100644 index 0000000..d0f67cf --- /dev/null +++ b/testdata/primeText.golden @@ -0,0 +1,135 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} + +// MarshalText implements the encoding.TextMarshaler interface for Prime +func (i Prime) MarshalText() ([]byte, error) { + return []byte(i.String()), nil +} + +// UnmarshalText implements the encoding.TextUnmarshaler interface for Prime +func (i *Prime) UnmarshalText(text []byte) error { + var err error + *i, err = PrimeString(string(text)) + return err +} diff --git a/testdata/primeYaml.golden b/testdata/primeYaml.golden new file mode 100644 index 0000000..555c53c --- /dev/null +++ b/testdata/primeYaml.golden @@ -0,0 +1,140 @@ + +const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" +const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43" + +var _PrimeMap = map[Prime]string{ + 2: _PrimeName[0:2], + 3: _PrimeName[2:4], + 5: _PrimeName[4:6], + 7: _PrimeName[6:8], + 11: _PrimeName[8:11], + 13: _PrimeName[11:14], + 17: _PrimeName[14:17], + 19: _PrimeName[17:20], + 23: _PrimeName[20:23], + 29: _PrimeName[23:26], + 31: _PrimeName[26:29], + 41: _PrimeName[29:32], + 43: _PrimeName[32:35], +} + +func (i Prime) String() string { + if str, ok := _PrimeMap[i]; ok { + return str + } + return fmt.Sprintf("Prime(%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 _PrimeNoOp() { + var x [1]struct{} + _ = x[p2-(2)] + _ = x[p3-(3)] + _ = x[p5-(5)] + _ = x[p7-(7)] + _ = x[p11-(11)] + _ = x[p13-(13)] + _ = x[p17-(17)] + _ = x[p19-(19)] + _ = x[p23-(23)] + _ = x[p29-(29)] + _ = x[p37-(31)] + _ = x[p41-(41)] + _ = x[p43-(43)] +} + +var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43} + +var _PrimeNameToValueMap = map[string]Prime{ + _PrimeName[0:2]: p2, + _PrimeLowerName[0:2]: p2, + _PrimeName[2:4]: p3, + _PrimeLowerName[2:4]: p3, + _PrimeName[4:6]: p5, + _PrimeLowerName[4:6]: p5, + _PrimeName[6:8]: p7, + _PrimeLowerName[6:8]: p7, + _PrimeName[8:11]: p11, + _PrimeLowerName[8:11]: p11, + _PrimeName[11:14]: p13, + _PrimeLowerName[11:14]: p13, + _PrimeName[14:17]: p17, + _PrimeLowerName[14:17]: p17, + _PrimeName[17:20]: p19, + _PrimeLowerName[17:20]: p19, + _PrimeName[20:23]: p23, + _PrimeLowerName[20:23]: p23, + _PrimeName[23:26]: p29, + _PrimeLowerName[23:26]: p29, + _PrimeName[26:29]: p37, + _PrimeLowerName[26:29]: p37, + _PrimeName[29:32]: p41, + _PrimeLowerName[29:32]: p41, + _PrimeName[32:35]: p43, + _PrimeLowerName[32:35]: p43, +} + +var _PrimeNames = []string{ + _PrimeName[0:2], + _PrimeName[2:4], + _PrimeName[4:6], + _PrimeName[6:8], + _PrimeName[8:11], + _PrimeName[11:14], + _PrimeName[14:17], + _PrimeName[17:20], + _PrimeName[20:23], + _PrimeName[23:26], + _PrimeName[26:29], + _PrimeName[29:32], + _PrimeName[32:35], +} + +// PrimeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PrimeString(s string) (Prime, error) { + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _PrimeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Prime values", s) +} + +// PrimeValues returns all values of the enum +func PrimeValues() []Prime { + return _PrimeValues +} + +// PrimeStrings returns a slice of all String values of the enum +func PrimeStrings() []string { + strs := make([]string, len(_PrimeNames)) + copy(strs, _PrimeNames) + return strs +} + +// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Prime) IsAPrime() bool { + _, ok := _PrimeMap[i] + return ok +} + +// MarshalYAML implements a YAML Marshaler for Prime +func (i Prime) MarshalYAML() (interface{}, error) { + return i.String(), nil +} + +// UnmarshalYAML implements a YAML Unmarshaler for Prime +func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + var err error + *i, err = PrimeString(s) + return err +} diff --git a/testdata/trimPrefix.golden b/testdata/trimPrefix.golden new file mode 100644 index 0000000..77db514 --- /dev/null +++ b/testdata/trimPrefix.golden @@ -0,0 +1,90 @@ + +const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" + +var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} + +const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[DayMonday-(0)] + _ = x[DayTuesday-(1)] + _ = x[DayWednesday-(2)] + _ = x[DayThursday-(3)] + _ = x[DayFriday-(4)] + _ = x[DaySaturday-(5)] + _ = x[DaySunday-(6)] +} + +var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:6]: DayMonday, + _DayLowerName[0:6]: DayMonday, + _DayName[6:13]: DayTuesday, + _DayLowerName[6:13]: DayTuesday, + _DayName[13:22]: DayWednesday, + _DayLowerName[13:22]: DayWednesday, + _DayName[22:30]: DayThursday, + _DayLowerName[22:30]: DayThursday, + _DayName[30:36]: DayFriday, + _DayLowerName[30:36]: DayFriday, + _DayName[36:44]: DaySaturday, + _DayLowerName[36:44]: DaySaturday, + _DayName[44:50]: DaySunday, + _DayLowerName[44:50]: DaySunday, +} + +var _DayNames = []string{ + _DayName[0:6], + _DayName[6:13], + _DayName[13:22], + _DayName[22:30], + _DayName[30:36], + _DayName[36:44], + _DayName[44:50], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/trimPrefixMultiple.golden b/testdata/trimPrefixMultiple.golden new file mode 100644 index 0000000..b40e6f0 --- /dev/null +++ b/testdata/trimPrefixMultiple.golden @@ -0,0 +1,90 @@ + +const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" + +var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} + +const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday" + +func (i Day) String() string { + if i < 0 || i >= Day(len(_DayIndex)-1) { + return fmt.Sprintf("Day(%d)", i) + } + return _DayName[_DayIndex[i]:_DayIndex[i+1]] +} + +// An "invalid array index" compiler error signifies that the constant values have changed. +// Re-run the stringer command to generate them again. +func _DayNoOp() { + var x [1]struct{} + _ = x[DayMonday-(0)] + _ = x[NightTuesday-(1)] + _ = x[DayWednesday-(2)] + _ = x[NightThursday-(3)] + _ = x[DayFriday-(4)] + _ = x[NightSaturday-(5)] + _ = x[DaySunday-(6)] +} + +var _DayValues = []Day{DayMonday, NightTuesday, DayWednesday, NightThursday, DayFriday, NightSaturday, DaySunday} + +var _DayNameToValueMap = map[string]Day{ + _DayName[0:6]: DayMonday, + _DayLowerName[0:6]: DayMonday, + _DayName[6:13]: NightTuesday, + _DayLowerName[6:13]: NightTuesday, + _DayName[13:22]: DayWednesday, + _DayLowerName[13:22]: DayWednesday, + _DayName[22:30]: NightThursday, + _DayLowerName[22:30]: NightThursday, + _DayName[30:36]: DayFriday, + _DayLowerName[30:36]: DayFriday, + _DayName[36:44]: NightSaturday, + _DayLowerName[36:44]: NightSaturday, + _DayName[44:50]: DaySunday, + _DayLowerName[44:50]: DaySunday, +} + +var _DayNames = []string{ + _DayName[0:6], + _DayName[6:13], + _DayName[13:22], + _DayName[22:30], + _DayName[30:36], + _DayName[36:44], + _DayName[44:50], +} + +// DayString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func DayString(s string) (Day, error) { + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + s = strings.ToLower(s) + if val, ok := _DayNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to Day values", s) +} + +// DayValues returns all values of the enum +func DayValues() []Day { + return _DayValues +} + +// DayStrings returns a slice of all String values of the enum +func DayStrings() []string { + strs := make([]string, len(_DayNames)) + copy(strs, _DayNames) + return strs +} + +// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise +func (i Day) IsADay() bool { + for _, v := range _DayValues { + if i == v { + return true + } + } + return false +} diff --git a/testdata/unum.golden b/testdata/unum.golden new file mode 100644 index 0000000..f496594 --- /dev/null +++ b/testdata/unum.golden @@ -0,0 +1,93 @@ + +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 +}