Skip to content

Commit c9e26e1

Browse files
authored
Merge pull request #25 from arran4/fix-uppercase-verbatim-17681050273744133828
fix: ensure UpperCaseWord preserves case in Verbatim mode
2 parents 48b990b + 5b80172 commit c9e26e1

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ func WordsToFormattedCase(words []Word, opts ...any) (string, error) {
386386
if err != nil {
387387
return "", err
388388
}
389-
} else {
390-
w = strings.ToLower(w)
391389
}
392390
case SeparatorWord:
393391
w = word.String()

types_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ func TestOptionUTF8Modes(t *testing.T) {
496496
},
497497
options: []Option{OptionCaseMode(CMAllTitle), OptionStrict()},
498498
expectErr: true,
499+
expected: "",
499500
},
500501
{
501502
name: "SingleCaseWord CMAllTitle Loose",
@@ -529,3 +530,28 @@ func TestOptionUTF8Modes(t *testing.T) {
529530
})
530531
}
531532
}
533+
534+
func TestUpperCaseWord_Verbatim_Bug(t *testing.T) {
535+
// "HELLO" is parsed as AcronymWord by default (SmartAcronyms=true).
536+
// But if SmartAcronyms=false, it becomes UpperCaseWord.
537+
538+
input := "HELLO"
539+
540+
// Case 1: Default (SmartAcronyms=true)
541+
words1, _ := Parse(input) // [AcronymWord("HELLO")]
542+
res1, _ := ToSnakeCase(words1) // ToSnakeCase defaults to Verbatim (but with delimiter "_")
543+
// AcronymWord preserves case by default.
544+
if res1 != "HELLO" {
545+
t.Errorf("Default behavior changed? Got %q, want %q", res1, "HELLO")
546+
}
547+
548+
// Case 2: SmartAcronyms=false
549+
words2, _ := Parse(input, WithSmartAcronyms(false)) // [UpperCaseWord("HELLO")]
550+
// Expectation: Verbatim mode should preserve case -> "HELLO"
551+
res2, _ := ToSnakeCase(words2)
552+
553+
expected := "HELLO"
554+
if res2 != expected {
555+
t.Errorf("UpperCaseWord (SmartAcronyms=false) did not preserve case. Got %q, want %q", res2, expected)
556+
}
557+
}

0 commit comments

Comments
 (0)