-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
msg_post_builder_test.go
87 lines (75 loc) · 2.46 KB
/
msg_post_builder_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package lark
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPostLocale(t *testing.T) {
pb := NewPostBuilder()
assert.Equal(t, defaultLocale, pb.curLocale)
pb.Locale(LocaleEnUS)
assert.Equal(t, LocaleEnUS, pb.curLocale)
pb.WithLocale(LocaleJaJP)
assert.Equal(t, LocaleJaJP, pb.curLocale)
}
func TestPostTitle(t *testing.T) {
pb := NewPostBuilder()
pb.Title("title")
assert.Equal(t, "title", pb.CurLocale().Title)
}
func TestPostTextTag(t *testing.T) {
pb := NewPostBuilder()
pb.TextTag("hello, world", 1, true)
buf := pb.CurLocale().Content
assert.Equal(t, "text", buf[0].Tag)
assert.Equal(t, "hello, world", *(buf[0].Text))
assert.Equal(t, 1, *(buf[0].Lines))
assert.Equal(t, true, *(buf[0].UnEscape))
}
func TestPostLinkTag(t *testing.T) {
pb := NewPostBuilder()
pb.LinkTag("hello, world", "https://www.toutiao.com/")
buf := pb.CurLocale().Content
assert.Equal(t, "a", buf[0].Tag)
assert.Equal(t, "hello, world", *(buf[0].Text))
assert.Equal(t, "https://www.toutiao.com/", *(buf[0].Href))
}
func TestPostAtTag(t *testing.T) {
pb := NewPostBuilder()
pb.AtTag("www", "123456")
buf := pb.CurLocale().Content
assert.Equal(t, "at", buf[0].Tag)
assert.Equal(t, "www", *(buf[0].Text))
assert.Equal(t, "123456", *(buf[0].UserID))
}
func TestPostImgTag(t *testing.T) {
pb := NewPostBuilder()
pb.ImageTag("d9f7d37e-c47c-411b-8ec6-9861132e6986", 320, 240)
buf := pb.CurLocale().Content
assert.Equal(t, "img", buf[0].Tag)
assert.Equal(t, "d9f7d37e-c47c-411b-8ec6-9861132e6986", *(buf[0].ImageKey))
assert.Equal(t, 240, *(buf[0].ImageHeight))
assert.Equal(t, 320, *(buf[0].ImageWidth))
}
func TestPostClearAndLen(t *testing.T) {
pb := NewPostBuilder()
pb.TextTag("hello, world", 1, true).LinkTag("link", "https://www.toutiao.com/")
assert.Equal(t, 2, pb.Len())
pb.Clear()
assert.Empty(t, pb.buf)
assert.Equal(t, 0, pb.Len())
}
func TestPostMultiLocaleContent(t *testing.T) {
pb := NewPostBuilder()
pb.Title("中文标题")
assert.Equal(t, "中文标题", pb.CurLocale().Title)
pb.TextTag("你好世界", 1, true).TextTag("其他内容", 1, true)
assert.Equal(t, 2, pb.Len())
pb.WithLocale(LocaleEnUS).Title("en title")
pb.TextTag("hello, world", 1, true).LinkTag("link", "https://www.toutiao.com/")
assert.Equal(t, 2, pb.Len())
assert.Equal(t, "en title", pb.CurLocale().Title)
content := pb.Render()
t.Log(content)
assert.Equal(t, "中文标题", (*content)[LocaleZhCN].Title)
assert.Equal(t, "en title", (*content)[LocaleEnUS].Title)
}