mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 12:28:54 +00:00
fix(wheelofnames): left-pad spoiler winner instead of centering
This commit is contained in:
1 parent
bf10149cb1
commit
c23fd132a6
2 files changed
+3
-5
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user