1
bot/common_test.go

36 lines
823 B
Go
Raw Permalink Normal View History

package bot
import "testing"
func TestEscapeMarkdown(t *testing.T) {
2023-01-19 16:13:19 +08:00
res := EscapeMarkdown("foo \\! _*[]()~`>#+-=|{}.! bar")
if res != "foo \\\\! \\_\\*\\[\\]\\(\\)\\~\\`\\>\\#\\+\\-\\=\\|\\{\\}\\.\\! bar" {
t.Fatalf("unexpected result %q", res)
}
}
func TestEscapeMarkdownUnescaped(t *testing.T) {
res := EscapeMarkdownUnescaped("foo \\! _*[]()~`>#+-=|{}.! bar")
if res != "foo \\! \\_\\*\\[\\]\\(\\)\\~\\`\\>\\#\\+\\-\\=\\|\\{\\}\\.\\! bar" {
t.Fatalf("unexpected result %q", res)
}
}
func TestRandomString(t *testing.T) {
res := map[string]struct{}{}
for i := 0; i < 100; i++ {
r := RandomString(10)
if _, ok := res[r]; ok {
t.Fatalf("value already exists")
}
res[r] = struct{}{}
}
for i := 10; i < 50; i++ {
r := RandomString(i)
if len(r) != i {
t.Fatalf("unexpected len")
}
}
}