File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,19 @@ const (
179179 simplePlural
180180)
181181
182+ func (f pluralForm ) String () string {
183+ switch f {
184+ case notPlural :
185+ return "notPlural"
186+ case invariantPlural :
187+ return "invariantPlural"
188+ case simplePlural :
189+ return "simplePlural"
190+ default :
191+ return "<unknown>"
192+ }
193+ }
194+
182195// pluralForm indicates how we want to pluralize a given initialism.
183196//
184197// Besides configured invariant forms (like HTTP and HTTPS),
Original file line number Diff line number Diff line change 77 "testing"
88
99 "github.com/go-openapi/testify/v2/assert"
10+ "github.com/go-openapi/testify/v2/require"
1011)
1112
1213const (
@@ -24,6 +25,16 @@ const (
2425 sampleUscore = "sample_"
2526)
2627
28+ func TestManglerToGoName_Issue158 (t * testing.T ) {
29+ m := NewNameMangler ()
30+
31+ t .Run ("should detect trailing pluralized initialisms" , func (t * testing.T ) {
32+ require .Equal (t , "LinkLocalIPs" , m .ToGoName ("LinkLocalIPs" ))
33+ require .Equal (t , "NativeBaseURLs" , m .ToGoName ("nativeBaseURLs" ))
34+ require .Equal (t , "SiteURLs" , m .ToGoName ("siteURLs" ))
35+ })
36+ }
37+
2738func TestManglerToGoName (t * testing.T ) {
2839 m := NewNameMangler ()
2940
Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ func (s splitter) gatherInitialismMatches(nameRunes []rune) *initialismMatches {
9090 continue
9191 }
9292
93+ if currentRunePosition - match .start == len (match .body ) {
94+ // unmatched: skip
95+ continue
96+ }
97+
9398 currentMatchRune := match .body [currentRunePosition - match .start ]
9499 if currentMatchRune != currentRune {
95100 // failed match, move on to next rune
@@ -160,7 +165,7 @@ func (s splitter) gatherInitialismMatches(nameRunes []rune) *initialismMatches {
160165 }
161166 }
162167
163- // check for new initialism matches
168+ // check for new initialism matches, based on the first character
164169 for i , r := range s .initialismsRunes {
165170 if r [0 ] == currentRune {
166171 * newMatches = append (* newMatches , initialismMatch {
You can’t perform that action at this time.
0 commit comments