refactor: чистка мёртвого кода, лимит ходов D3, HTML-экранирование и UTF-8 обрезка в Telegram
Some checks failed
CI / test (pull_request) Failing after 34s
CI / build-and-package (amd64, linux) (pull_request) Successful in 34s
CI / build-and-package (amd64, windows) (pull_request) Successful in 36s

This commit is contained in:
ki.sagidullin
2026-08-18 23:13:04 +05:00
parent 7eb3a0292c
commit 1459670ce9
13 changed files with 138 additions and 190 deletions

View File

@@ -9,6 +9,7 @@ import (
"sync"
"testing"
"time"
"unicode/utf8"
"github.com/kamelion/ratatoskr-go/internal/chat"
)
@@ -111,6 +112,36 @@ func TestSendWithOptions(t *testing.T) {
}
}
func TestFormatOutgoingEscapesText(t *testing.T) {
if got := formatOutgoing(chat.Message{Text: "2 < 3 & 4 > 1"}); got != "2 &lt; 3 &amp; 4 &gt; 1" {
t.Errorf("text escape = %q", got)
}
got := formatOutgoing(chat.Message{
Text: "a<b",
Options: []chat.Option{{ID: "x", Label: "l&l"}},
})
if !strings.Contains(got, "a&lt;b") || !strings.Contains(got, "l&amp;l") {
t.Errorf("options escape = %q", got)
}
}
func TestTruncateUTF8(t *testing.T) {
long := strings.Repeat("я", 5000)
tr := truncateUTF8(long, 4000)
if len(tr) != 4000 {
t.Fatalf("len = %d, want 4000", len(tr))
}
if !utf8.ValidString(tr) {
t.Fatal("truncated string is not valid UTF-8")
}
if got := truncateUTF8("привет", 4000); got != "привет" {
t.Fatalf("short text changed: %q", got)
}
if got := truncateUTF8("", 4000); got != "" {
t.Fatalf("empty text changed: %q", got)
}
}
func TestIncoming(t *testing.T) {
f := newFakeTG(t)
ch := New("TOKEN", time.Second)
@@ -143,4 +174,4 @@ func TestIncoming(t *testing.T) {
case <-ctx.Done():
t.Fatal("timeout ожидания входящего")
}
}
}