2023-01-19 15:59:16 +08:00
|
|
|
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" {
|
2023-01-19 15:59:16 +08:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|