From b85f109b7fa639e0d1c1532eed82520e1b2e7854 Mon Sep 17 00:00:00 2001 From: Dan Markham Date: Tue, 22 Jun 2021 21:20:35 -0700 Subject: [PATCH] Return the same string passed for error Fixes Issue #43 --- .travis.yml | 4 ++-- README.md | 2 +- enumer.go | 4 ++-- testdata/day.golden | 4 ++-- testdata/dayTrimAndPrefix.golden | 4 ++-- testdata/dayWithLinecomment.golden | 4 ++-- testdata/dayWithPrefix.golden | 4 ++-- testdata/gap.golden | 4 ++-- testdata/num.golden | 4 ++-- testdata/offset.golden | 4 ++-- testdata/prime.golden | 4 ++-- testdata/primeGQLGen.golden | 4 ++-- testdata/primeJson.golden | 4 ++-- testdata/primeJsonAndSql.golden | 4 ++-- testdata/primeSql.golden | 4 ++-- testdata/primeText.golden | 4 ++-- testdata/primeYaml.golden | 4 ++-- testdata/trimPrefix.golden | 4 ++-- testdata/trimPrefixMultiple.golden | 4 ++-- testdata/unum.golden | 4 ++-- 20 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7bd3a05..5919f98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ matrix: allow_failures: - go: master include: - - go: 1.14.x - go: 1.15.x + - go: 1.16.x - go: master env: global: @@ -24,6 +24,6 @@ deploy: - cli/build/enumer.windows-amd64.exe.tar.gz - cli/build/sha256sum.txt on: - go: 1.15.x + go: 1.16.x repo: dmarkham/enumer tags: true diff --git a/README.md b/README.md index 24e4376..7f5e78e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 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) +# 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) Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type). diff --git a/enumer.go b/enumer.go index 3cb1f5d..cfdc3a2 100644 --- a/enumer.go +++ b/enumer.go @@ -10,8 +10,8 @@ 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 { + + if val, ok := _%[1]sNameToValueMap[strings.ToLower(s)]; ok { return val, nil } return 0, fmt.Errorf("%%s does not belong to %[1]s values", s) diff --git a/testdata/day.golden b/testdata/day.golden index fd4a481..537b04b 100644 --- a/testdata/day.golden +++ b/testdata/day.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 c3afe9e..7f5367d 100644 --- a/testdata/dayTrimAndPrefix.golden +++ b/testdata/dayTrimAndPrefix.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 6b5dfdb..c6b8584 100644 --- a/testdata/dayWithLinecomment.golden +++ b/testdata/dayWithLinecomment.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 03a9280..d468741 100644 --- a/testdata/dayWithPrefix.golden +++ b/testdata/dayWithPrefix.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 6561679..129891e 100644 --- a/testdata/gap.golden +++ b/testdata/gap.golden @@ -81,8 +81,8 @@ 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 { + + if val, ok := _GapNameToValueMap[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 f496953..1a5407f 100644 --- a/testdata/num.golden +++ b/testdata/num.golden @@ -53,8 +53,8 @@ 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 { + + if val, ok := _NumNameToValueMap[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 69e91a9..44cc102 100644 --- a/testdata/offset.golden +++ b/testdata/offset.golden @@ -45,8 +45,8 @@ 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 { + + if val, ok := _NumberNameToValueMap[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 1719eac..283dbd1 100644 --- a/testdata/prime.golden +++ b/testdata/prime.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 3ff7ba5..14c8eff 100644 --- a/testdata/primeGQLGen.golden +++ b/testdata/primeGQLGen.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 8b1e82f..9224728 100644 --- a/testdata/primeJson.golden +++ b/testdata/primeJson.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 8449e6a..1133b4a 100644 --- a/testdata/primeJsonAndSql.golden +++ b/testdata/primeJsonAndSql.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 d12a764..9a5292a 100644 --- a/testdata/primeSql.golden +++ b/testdata/primeSql.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 d0f67cf..e8102d6 100644 --- a/testdata/primeText.golden +++ b/testdata/primeText.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 555c53c..5197219 100644 --- a/testdata/primeYaml.golden +++ b/testdata/primeYaml.golden @@ -97,8 +97,8 @@ 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 { + + if val, ok := _PrimeNameToValueMap[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 77db514..52f063e 100644 --- a/testdata/trimPrefix.golden +++ b/testdata/trimPrefix.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 b40e6f0..439ca92 100644 --- a/testdata/trimPrefixMultiple.golden +++ b/testdata/trimPrefixMultiple.golden @@ -60,8 +60,8 @@ 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 { + + if val, ok := _DayNameToValueMap[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 f496594..ed149b5 100644 --- a/testdata/unum.golden +++ b/testdata/unum.golden @@ -63,8 +63,8 @@ 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 { + + if val, ok := _UnumNameToValueMap[strings.ToLower(s)]; ok { return val, nil } return 0, fmt.Errorf("%s does not belong to Unum values", s)