tgbot_send_test.go 959 B

1234567891011121314151617181920212223242526272829303132333435
  1. package tgbot
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestPageMessageSplitsLinkListWithoutBlankLines(t *testing.T) {
  7. var message strings.Builder
  8. message.WriteString("Individual links:\r\n")
  9. for range 50 {
  10. message.WriteString("<code>vless://" + strings.Repeat("a", 300) + "</code>\r\n")
  11. }
  12. pages := pageMessage(message.String(), telegramPageLimit)
  13. if len(pages) < 2 {
  14. t.Fatalf("pageMessage() returned %d page, want multiple", len(pages))
  15. }
  16. links := 0
  17. for index, page := range pages {
  18. if len(page) > telegramPageLimit {
  19. t.Errorf("page %d has %d bytes, want at most %d", index, len(page), telegramPageLimit)
  20. }
  21. openingTags := strings.Count(page, "<code>")
  22. closingTags := strings.Count(page, "</code>")
  23. if openingTags != closingTags {
  24. t.Errorf("page %d has %d opening tags and %d closing tags", index, openingTags, closingTags)
  25. }
  26. links += openingTags
  27. }
  28. if links != 50 {
  29. t.Errorf("pages contain %d links, want 50", links)
  30. }
  31. }