Move to Go 1.27, and fix initials for non-ASCII names
Initials() capped the loop with len(out) == 2, which counts bytes: a name starting with Ä, Ö or Å filled the budget on its own and returned a single letter. Count the initials taken instead. go fix also wanted a strings.Builder here, but that allocates a string per iteration to measure a two-character result. Took its SplitSeq suggestion in lyrics.go, which drops an intermediate slice.
This commit is contained in:
@@ -230,3 +230,17 @@ func TestBanDropsSessionsAndBlocksLogin(t *testing.T) {
|
||||
t.Fatalf("login after unban: status = %d, want 303", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitials(t *testing.T) {
|
||||
for name, want := range map[string]string{
|
||||
"Esa Kataja": "EK",
|
||||
"Ärväs Öhman": "ÄÖ", // multi-byte initials must not end the loop early
|
||||
"Åke": "Å",
|
||||
"": "",
|
||||
"a b c": "AB",
|
||||
} {
|
||||
if got := (&member{Name: name}).Initials(); got != want {
|
||||
t.Errorf("Initials(%q) = %q, want %q", name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user