Skip to content

Commit d7da2ad

Browse files
committed
Fix issue with test
1 parent 118351e commit d7da2ad

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

strmangle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func titleCase(n string, trimLeftDigits bool) string {
304304
// If the string is made up of only uppercase letters and underscores,
305305
// then return as is and do not strip the underscores
306306
// This keeps strings such as PUBLIC_KEY readable and not make it PUBLICKEY
307-
if cleanN == strings.ToUpper(cleanN) {
307+
if len(n) == len(cleanN) && n == strings.ToUpper(n) {
308308
// Cache the title case as the same string
309309
mut.Lock()
310310
titleCaseCache[n] = cleanN

strmangle_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ func TestTrimLeftDigits(t *testing.T) {
204204
}
205205
}
206206

207+
func TestSanitizeForIdentifier(t *testing.T) {
208+
t.Parallel()
209+
210+
tests := []struct {
211+
In string
212+
Out string
213+
}{
214+
// No changes:
215+
{"hello_there&", "hello_there_"},
216+
{"FOO/BAR", "FOO_BAR"},
217+
}
218+
219+
for i, test := range tests {
220+
if out := sanitizeForIdentifier(test.In); out != test.Out {
221+
t.Errorf("[%d] (%s) Out was wrong: %q, want: %q", i, test.In, out, test.Out)
222+
}
223+
}
224+
}
225+
207226
func clearTitleCaseCache() {
208227
mut.RLock()
209228
titleCaseCache = map[string]string{}
@@ -233,6 +252,7 @@ func TestTitleCaseFull(t *testing.T) {
233252
{"im_418_years_old", "Im418YearsOld"},
234253
{"im_418years_old", "Im418yearsOld"},
235254
{"418im_a_teapot", "ImATeapot"},
255+
{"FOO/BAR", "FOO_BAR"},
236256
}
237257

238258
for i, test := range tests {

0 commit comments

Comments
 (0)