mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-25 12:27:13 +00:00
f13baa9af5
Individual-link batches contain single line breaks, so the previous blank-line-only pagination could send oversized replies unchanged. Co-authored-by: sanmaxdev <sanmaxdev@users.noreply.github.com>
36 lines
959 B
Go
36 lines
959 B
Go
package tgbot
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPageMessageSplitsLinkListWithoutBlankLines(t *testing.T) {
|
|
var message strings.Builder
|
|
message.WriteString("Individual links:\r\n")
|
|
for range 50 {
|
|
message.WriteString("<code>vless://" + strings.Repeat("a", 300) + "</code>\r\n")
|
|
}
|
|
|
|
pages := pageMessage(message.String(), telegramPageLimit)
|
|
if len(pages) < 2 {
|
|
t.Fatalf("pageMessage() returned %d page, want multiple", len(pages))
|
|
}
|
|
|
|
links := 0
|
|
for index, page := range pages {
|
|
if len(page) > telegramPageLimit {
|
|
t.Errorf("page %d has %d bytes, want at most %d", index, len(page), telegramPageLimit)
|
|
}
|
|
openingTags := strings.Count(page, "<code>")
|
|
closingTags := strings.Count(page, "</code>")
|
|
if openingTags != closingTags {
|
|
t.Errorf("page %d has %d opening tags and %d closing tags", index, openingTags, closingTags)
|
|
}
|
|
links += openingTags
|
|
}
|
|
if links != 50 {
|
|
t.Errorf("pages contain %d links, want 50", links)
|
|
}
|
|
}
|