fix: Move lower-cased names to a separate map to fix overlapping cases

This commit is contained in:
Gabe Cook 2024-10-11 01:46:20 -05:00
parent bcbe6173c3
commit 34ad3cd961
No known key found for this signature in database
GPG Key ID: 3197318BDE319B8D
18 changed files with 246 additions and 172 deletions

View File

@ -11,7 +11,7 @@ func %[1]sString(s string) (%[1]s, error) {
return val, nil
}
if val, ok := _%[1]sNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _%[1]sLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)
@ -84,6 +84,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh
// Print the map between name and value
g.printValueMap(runs, typeName, runsThreshold)
g.printLowerValueMap(runs, typeName, runsThreshold)
// Print the slice of names
g.printNamesSlice(runs, typeName, runsThreshold)
@ -115,12 +116,34 @@ func (g *Generator) printValueMap(runs [][]Value, typeName string, runsThreshold
for _, value := range values {
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
n += len(value.name)
}
}
g.Printf("}\n\n")
}
func (g *Generator) printLowerValueMap(runs [][]Value, typeName string, runsThreshold int) {
thereAreRuns := len(runs) > 1 && len(runs) <= runsThreshold
g.Printf("\nvar _%sLowerNameToValueMap = map[string]%s{\n", typeName, typeName)
var n int
var runID string
for i, values := range runs {
if thereAreRuns {
runID = "_" + fmt.Sprintf("%d", i)
n = 0
} else {
runID = ""
}
for _, value := range values {
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
n += len(value.name)
}
}
g.Printf("}\n\n")
}
func (g *Generator) printNamesSlice(runs [][]Value, typeName string, runsThreshold int) {
thereAreRuns := len(runs) > 1 && len(runs) <= runsThreshold
g.Printf("\nvar _%sNames = []string{\n", typeName)

19
testdata/day.golden vendored
View File

@ -32,19 +32,22 @@ func _DayNoOp() {
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:6]: Monday,
_DayName[0:6]: Monday,
_DayName[6:13]: Tuesday,
_DayName[13:22]: Wednesday,
_DayName[22:30]: Thursday,
_DayName[30:36]: Friday,
_DayName[36:44]: Saturday,
_DayName[44:50]: Sunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -65,7 +68,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

View File

@ -28,19 +28,22 @@ func _DayNoOp() {
var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:11]: DayMonday,
_DayName[0:11]: DayMonday,
_DayName[11:23]: DayTuesday,
_DayName[23:37]: DayWednesday,
_DayName[37:50]: DayThursday,
_DayName[50:61]: DayFriday,
_DayName[61:74]: DaySaturday,
_DayName[74:85]: DaySunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -61,7 +64,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

View File

@ -28,19 +28,22 @@ func _DayNoOp() {
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:5]: Monday,
_DayName[0:5]: Monday,
_DayName[5:12]: Tuesday,
_DayName[12:21]: Wednesday,
_DayName[21:29]: Thursday,
_DayName[29:36]: Friday,
_DayName[36:44]: Saturday,
_DayName[44:50]: Sunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -61,7 +64,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

View File

@ -28,19 +28,22 @@ func _DayNoOp() {
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:9]: Monday,
_DayName[0:9]: Monday,
_DayName[9:19]: Tuesday,
_DayName[19:31]: Wednesday,
_DayName[31:42]: Thursday,
_DayName[42:51]: Friday,
_DayName[51:62]: Saturday,
_DayName[62:71]: Sunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -61,7 +64,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

21
testdata/gap.golden vendored
View File

@ -50,21 +50,24 @@ func _GapNoOp() {
var _GapValues = []Gap{Two, Three, Five, Six, Seven, Eight, Nine, Eleven}
var _GapNameToValueMap = map[string]Gap{
_GapName_0[0:3]: Two,
_GapName_0[0:3]: Two,
_GapName_0[3:8]: Three,
_GapName_1[0:4]: Five,
_GapName_1[4:7]: Six,
_GapName_1[7:12]: Seven,
_GapName_1[12:17]: Eight,
_GapName_1[17:21]: Nine,
_GapName_2[0:6]: Eleven,
}
var _GapLowerNameToValueMap = map[string]Gap{
_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,
}
@ -86,7 +89,7 @@ func GapString(s string) (Gap, error) {
return val, nil
}
if val, ok := _GapNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _GapLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Gap values", s)

15
testdata/num.golden vendored
View File

@ -31,15 +31,18 @@ func _NumNoOp() {
var _NumValues = []Num{m_2, m_1, m0, m1, m2}
var _NumNameToValueMap = map[string]Num{
_NumName[0:3]: m_2,
_NumName[0:3]: m_2,
_NumName[3:6]: m_1,
_NumName[6:8]: m0,
_NumName[8:10]: m1,
_NumName[10:12]: m2,
}
var _NumLowerNameToValueMap = map[string]Num{
_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,
}
@ -58,7 +61,7 @@ func NumString(s string) (Num, error) {
return val, nil
}
if val, ok := _NumNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _NumLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Num values", s)

View File

@ -29,11 +29,14 @@ func _NumberNoOp() {
var _NumberValues = []Number{One, Two, Three}
var _NumberNameToValueMap = map[string]Number{
_NumberName[0:3]: One,
_NumberName[0:3]: One,
_NumberName[3:6]: Two,
_NumberName[6:11]: Three,
}
var _NumberLowerNameToValueMap = map[string]Number{
_NumberLowerName[0:3]: One,
_NumberName[3:6]: Two,
_NumberLowerName[3:6]: Two,
_NumberName[6:11]: Three,
_NumberLowerName[6:11]: Three,
}
@ -50,7 +53,7 @@ func NumberString(s string) (Number, error) {
return val, nil
}
if val, ok := _NumberNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _NumberLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Number values", s)

31
testdata/prime.golden vendored
View File

@ -51,31 +51,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -102,7 +105,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -47,31 +47,34 @@ func _PrimeNoOp() {
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,
_PrimeName[0:2]: p2,
_PrimeName[2:4]: p3,
_PrimeName[4:6]: p5,
_PrimeName[6:8]: p7,
_PrimeName[8:11]: p11,
_PrimeName[11:14]: p13,
_PrimeName[14:17]: p17,
_PrimeName[17:20]: p19,
_PrimeName[20:23]: p23,
_PrimeName[23:26]: p29,
_PrimeName[26:29]: p37,
_PrimeName[29:32]: p41,
_PrimeName[32:35]: p43,
}
var _PrimeLowerNameToValueMap = map[string]Prime{
_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,
}
@ -98,7 +101,7 @@ func PrimeString(s string) (Prime, error) {
return val, nil
}
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _PrimeLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Prime values", s)

View File

@ -28,19 +28,22 @@ func _DayNoOp() {
var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:6]: DayMonday,
_DayName[0:6]: DayMonday,
_DayName[6:13]: DayTuesday,
_DayName[13:22]: DayWednesday,
_DayName[22:30]: DayThursday,
_DayName[30:36]: DayFriday,
_DayName[36:44]: DaySaturday,
_DayName[44:50]: DaySunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -61,7 +64,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

View File

@ -28,19 +28,22 @@ func _DayNoOp() {
var _DayValues = []Day{DayMonday, NightTuesday, DayWednesday, NightThursday, DayFriday, NightSaturday, DaySunday}
var _DayNameToValueMap = map[string]Day{
_DayName[0:6]: DayMonday,
_DayName[0:6]: DayMonday,
_DayName[6:13]: NightTuesday,
_DayName[13:22]: DayWednesday,
_DayName[22:30]: NightThursday,
_DayName[30:36]: DayFriday,
_DayName[36:44]: NightSaturday,
_DayName[44:50]: DaySunday,
}
var _DayLowerNameToValueMap = map[string]Day{
_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,
}
@ -61,7 +64,7 @@ func DayString(s string) (Day, error) {
return val, nil
}
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _DayLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Day values", s)

15
testdata/unum.golden vendored
View File

@ -41,15 +41,18 @@ func _UnumNoOp() {
var _UnumValues = []Unum{m0, m1, m2, m_2, m_1}
var _UnumNameToValueMap = map[string]Unum{
_UnumName_0[0:2]: m0,
_UnumName_0[0:2]: m0,
_UnumName_0[2:4]: m1,
_UnumName_0[4:6]: m2,
_UnumName_1[0:3]: m_2,
_UnumName_1[3:6]: m_1,
}
var _UnumLowerNameToValueMap = map[string]Unum{
_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,
}
@ -68,7 +71,7 @@ func UnumString(s string) (Unum, error) {
return val, nil
}
if val, ok := _UnumNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _UnumLowerNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Unum values", s)