Skip to content

Commit 9d0b7d4

Browse files
authored
Merge pull request #44 from dmarkham/dan/issue-43
Return the same string passed for error
2 parents 677b61c + b85f109 commit 9d0b7d4

20 files changed

+39
-39
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ matrix:
44
allow_failures:
55
- go: master
66
include:
7-
- go: 1.14.x
87
- go: 1.15.x
8+
- go: 1.16.x
99
- go: master
1010
env:
1111
global:
@@ -24,6 +24,6 @@ deploy:
2424
- cli/build/enumer.windows-amd64.exe.tar.gz
2525
- cli/build/sha256sum.txt
2626
on:
27-
go: 1.15.x
27+
go: 1.16.x
2828
repo: dmarkham/enumer
2929
tags: true

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enumer [![GoDoc](https://godoc.org/github.com/dmarkham/enumer?status.svg)](https://godoc.org/github.com/dmarkham/enumer) [![Go Report Card](https://goreportcard.com/badge/github.com/dmarkham/enumer)](https://goreportcard.com/report/github.com/dmarkham/enumer) [![GitHub Release](https://img.shields.io/github/release/dmarkham/enumer.svg)](https://github.com/dmarkham/enumer/releases)[![Build Status](https://travis-ci.org/dmarkham/enumer.svg?branch=master)](https://travis-ci.org/dmarkham/enumer)
1+
# Enumer [![GoDoc](https://godoc.org/github.com/dmarkham/enumer?status.svg)](https://godoc.org/github.com/dmarkham/enumer) [![Go Report Card](https://goreportcard.com/badge/github.com/dmarkham/enumer)](https://goreportcard.com/report/github.com/dmarkham/enumer) [![GitHub Release](https://img.shields.io/github/release/dmarkham/enumer.svg)](https://github.com/dmarkham/enumer/releases)[![Build Status](https://travis-ci.com/dmarkham/enumer.svg?branch=master)](https://travis-ci.com/dmarkham/enumer)
22

33

44
Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).

enumer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func %[1]sString(s string) (%[1]s, error) {
1010
if val, ok := _%[1]sNameToValueMap[s]; ok {
1111
return val, nil
1212
}
13-
s = strings.ToLower(s)
14-
if val, ok := _%[1]sNameToValueMap[s]; ok {
13+
14+
if val, ok := _%[1]sNameToValueMap[strings.ToLower(s)]; ok {
1515
return val, nil
1616
}
1717
return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)

testdata/day.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/dayTrimAndPrefix.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/dayWithLinecomment.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/dayWithPrefix.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/gap.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func GapString(s string) (Gap, error) {
8181
if val, ok := _GapNameToValueMap[s]; ok {
8282
return val, nil
8383
}
84-
s = strings.ToLower(s)
85-
if val, ok := _GapNameToValueMap[s]; ok {
84+
85+
if val, ok := _GapNameToValueMap[strings.ToLower(s)]; ok {
8686
return val, nil
8787
}
8888
return 0, fmt.Errorf("%s does not belong to Gap values", s)

testdata/num.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func NumString(s string) (Num, error) {
5353
if val, ok := _NumNameToValueMap[s]; ok {
5454
return val, nil
5555
}
56-
s = strings.ToLower(s)
57-
if val, ok := _NumNameToValueMap[s]; ok {
56+
57+
if val, ok := _NumNameToValueMap[strings.ToLower(s)]; ok {
5858
return val, nil
5959
}
6060
return 0, fmt.Errorf("%s does not belong to Num values", s)

testdata/offset.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func NumberString(s string) (Number, error) {
4545
if val, ok := _NumberNameToValueMap[s]; ok {
4646
return val, nil
4747
}
48-
s = strings.ToLower(s)
49-
if val, ok := _NumberNameToValueMap[s]; ok {
48+
49+
if val, ok := _NumberNameToValueMap[strings.ToLower(s)]; ok {
5050
return val, nil
5151
}
5252
return 0, fmt.Errorf("%s does not belong to Number values", s)

testdata/prime.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeGQLGen.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeJson.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeJsonAndSql.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeSql.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeText.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/primeYaml.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func PrimeString(s string) (Prime, error) {
9797
if val, ok := _PrimeNameToValueMap[s]; ok {
9898
return val, nil
9999
}
100-
s = strings.ToLower(s)
101-
if val, ok := _PrimeNameToValueMap[s]; ok {
100+
101+
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
102102
return val, nil
103103
}
104104
return 0, fmt.Errorf("%s does not belong to Prime values", s)

testdata/trimPrefix.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/trimPrefixMultiple.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func DayString(s string) (Day, error) {
6060
if val, ok := _DayNameToValueMap[s]; ok {
6161
return val, nil
6262
}
63-
s = strings.ToLower(s)
64-
if val, ok := _DayNameToValueMap[s]; ok {
63+
64+
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
6565
return val, nil
6666
}
6767
return 0, fmt.Errorf("%s does not belong to Day values", s)

testdata/unum.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func UnumString(s string) (Unum, error) {
6363
if val, ok := _UnumNameToValueMap[s]; ok {
6464
return val, nil
6565
}
66-
s = strings.ToLower(s)
67-
if val, ok := _UnumNameToValueMap[s]; ok {
66+
67+
if val, ok := _UnumNameToValueMap[strings.ToLower(s)]; ok {
6868
return val, nil
6969
}
7070
return 0, fmt.Errorf("%s does not belong to Unum values", s)

0 commit comments

Comments
 (0)