forked from go-telegram/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
35 lines (30 loc) · 823 Bytes
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bot
import "testing"
func TestEscapeMarkdown(t *testing.T) {
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")
}
}
}