fix(wheelofnames): left-pad spoiler winner instead of centering

This commit is contained in:
tiennm99 committed 2026-08-06 11:09:26 +07:00
1 parent bf10149cb1
commit c23fd132a6
2 files changed
+3 -5

No files matched your search

+1 -1
View File
@@ -168,7 +168,7 @@ func TestWheelOfNames_ResultCaptionTruncatesLongResult(t *testing.T) {
func TestWheelOfNames_ResultCaptionPadsShortWinnerToLongestOption(t *testing.T) {
options := []string{"Bob", "Alexandria"}
got := wheelResultCaption(options, 0)
want := `Result: <span class="tg-spoiler">` + strings.Repeat(wheelCaptionPad, 3) + "Bob" + strings.Repeat(wheelCaptionPad, 4) + `</span>`
want := `Result: <span class="tg-spoiler">` + strings.Repeat(wheelCaptionPad, 7) + "Bob" + `</span>`
if got != want {
t.Fatalf("wheelResultCaption() = %q, want %q", got, want)
}
@@ -75,7 +75,7 @@ func wheelResultCaption(options []string, winner int) string {
// Telegram, which would shrink the spoiler and reveal the winner's length.
const wheelCaptionPad = "\u00a0"
// padWheelResultCaption centers shorter winners with blank padding so every
// padWheelResultCaption prefixes shorter winners with blank padding so every
// option renders a spoiler of equal length; otherwise the spoiler width
// reveals the winner. The longest option is returned unpadded.
func padWheelResultCaption(options []string, result string) string {
@@ -85,9 +85,7 @@ func padWheelResultCaption(options []string, result string) string {
longest = n
}
}
missing := longest - len([]rune(result))
left := missing / 2
return strings.Repeat(wheelCaptionPad, left) + result + strings.Repeat(wheelCaptionPad, missing-left)
return strings.Repeat(wheelCaptionPad, longest-len([]rune(result))) + result
}
func truncateWheelResultCaption(result string) string {