diff --git a/enumer.go b/enumer.go index c234209..022aa12 100644 --- a/enumer.go +++ b/enumer.go @@ -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) diff --git a/testdata/day.golden b/testdata/day.golden index f23e69b..56ecae8 100644 --- a/testdata/day.golden +++ b/testdata/day.golden @@ -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) diff --git a/testdata/dayTrimAndPrefix.golden b/testdata/dayTrimAndPrefix.golden index 7f5367d..6ced25c 100644 --- a/testdata/dayTrimAndPrefix.golden +++ b/testdata/dayTrimAndPrefix.golden @@ -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) diff --git a/testdata/dayWithLinecomment.golden b/testdata/dayWithLinecomment.golden index c6b8584..d2d500a 100644 --- a/testdata/dayWithLinecomment.golden +++ b/testdata/dayWithLinecomment.golden @@ -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) diff --git a/testdata/dayWithPrefix.golden b/testdata/dayWithPrefix.golden index d468741..f787ddb 100644 --- a/testdata/dayWithPrefix.golden +++ b/testdata/dayWithPrefix.golden @@ -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) diff --git a/testdata/gap.golden b/testdata/gap.golden index cc3e48d..db51937 100644 --- a/testdata/gap.golden +++ b/testdata/gap.golden @@ -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) diff --git a/testdata/num.golden b/testdata/num.golden index 97cc937..9eec78d 100644 --- a/testdata/num.golden +++ b/testdata/num.golden @@ -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) diff --git a/testdata/offset.golden b/testdata/offset.golden index 0e52817..c0c6dd3 100644 --- a/testdata/offset.golden +++ b/testdata/offset.golden @@ -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) diff --git a/testdata/prime.golden b/testdata/prime.golden index 8783338..ca4f420 100644 --- a/testdata/prime.golden +++ b/testdata/prime.golden @@ -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) diff --git a/testdata/primeGQLGen.golden b/testdata/primeGQLGen.golden index 14c8eff..354cddf 100644 --- a/testdata/primeGQLGen.golden +++ b/testdata/primeGQLGen.golden @@ -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) diff --git a/testdata/primeJson.golden b/testdata/primeJson.golden index 9224728..286ae56 100644 --- a/testdata/primeJson.golden +++ b/testdata/primeJson.golden @@ -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) diff --git a/testdata/primeJsonAndSql.golden b/testdata/primeJsonAndSql.golden index 1133b4a..f4e6bfe 100644 --- a/testdata/primeJsonAndSql.golden +++ b/testdata/primeJsonAndSql.golden @@ -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) diff --git a/testdata/primeSql.golden b/testdata/primeSql.golden index 9a5292a..1ed2a54 100644 --- a/testdata/primeSql.golden +++ b/testdata/primeSql.golden @@ -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) diff --git a/testdata/primeText.golden b/testdata/primeText.golden index e8102d6..adf10e6 100644 --- a/testdata/primeText.golden +++ b/testdata/primeText.golden @@ -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) diff --git a/testdata/primeYaml.golden b/testdata/primeYaml.golden index 5197219..634b0a0 100644 --- a/testdata/primeYaml.golden +++ b/testdata/primeYaml.golden @@ -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) diff --git a/testdata/trimPrefix.golden b/testdata/trimPrefix.golden index 52f063e..0b3b1af 100644 --- a/testdata/trimPrefix.golden +++ b/testdata/trimPrefix.golden @@ -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) diff --git a/testdata/trimPrefixMultiple.golden b/testdata/trimPrefixMultiple.golden index 439ca92..11cf151 100644 --- a/testdata/trimPrefixMultiple.golden +++ b/testdata/trimPrefixMultiple.golden @@ -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) diff --git a/testdata/unum.golden b/testdata/unum.golden index 9e413dc..440ac00 100644 --- a/testdata/unum.golden +++ b/testdata/unum.golden @@ -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)