-
Notifications
You must be signed in to change notification settings - Fork 11
/
parse_mode_test.go
64 lines (56 loc) · 3.07 KB
/
parse_mode_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
package tg
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseModeHTML(t *testing.T) {
assert.Equal(t, "HTML", HTML.String())
marshaled, err := HTML.MarshalText()
assert.NoError(t, err)
assert.Equal(t, "HTML", string(marshaled))
assert.Equal(t, "Hello World", HTML.Line("Hello", "World"))
assert.Equal(t, "Hello\nWorld", HTML.Text("Hello", "World"))
assert.Equal(t, "<b>Hello World</b>", HTML.Bold("Hello", "World"))
assert.Equal(t, "<i>Hello World</i>", HTML.Italic("Hello", "World"))
assert.Equal(t, "<u>Hello World</u>", HTML.Underline("Hello", "World"))
assert.Equal(t, "<s>Hello World</s>", HTML.Strike("Hello", "World"))
assert.Equal(t, "<tg-spoiler>Hello World</tg-spoiler>", HTML.Spoiler("Hello", "World"))
assert.Equal(t, "<a href=\"https://telegram.org\">Hello World</a>", HTML.Link("Hello World", "https://telegram.org"))
assert.Equal(t, "<code>Hello World</code>", HTML.Code("Hello World"))
assert.Equal(t, "<pre>Hello World</pre>", HTML.Pre("Hello World"))
assert.Equal(t, "<b>Hello, World</b>", HTML.Sep(", ").Bold("Hello", "World"))
assert.Equal(t, "<blockquote>Hello, World</blockquote>", HTML.Sep(", ").Blockquote("Hello", "World"))
assert.Equal(t, "Me & You", HTML.Escape("Me & You"))
}
func TestParseModeMarkdown(t *testing.T) {
assert.Equal(t, "Markdown", MD.String())
assert.Equal(t, "Hello World", MD.Line("Hello", "World"))
assert.Equal(t, "Hello\nWorld", MD.Text("Hello", "World"))
assert.Equal(t, "*Hello World*", MD.Bold("Hello", "World"))
assert.Equal(t, "_Hello World_", MD.Italic("Hello", "World"))
assert.Equal(t, "Hello World", MD.Underline("Hello", "World"))
assert.Equal(t, "Hello World", MD.Strike("Hello", "World"))
assert.Equal(t, "Hello World", MD.Spoiler("Hello", "World"))
assert.Equal(t, "[Hello World](https://telegram.org)", MD.Link("Hello World", "https://telegram.org"))
assert.Equal(t, "`Hello World`", MD.Code("Hello World"))
assert.Equal(t, "```Hello World```", MD.Pre("Hello World"))
assert.Equal(t, "*Hello, World*", MD.Sep(", ").Bold("Hello", "World"))
assert.Equal(t, "\\*go\\_tg\\*", MD.Escape("*go_tg*"))
}
func TestParseModeMarkdownV2(t *testing.T) {
assert.Equal(t, "MarkdownV2", MD2.String())
assert.Equal(t, "Hello World", MD2.Line("Hello", "World"))
assert.Equal(t, "Hello\nWorld", MD2.Text("Hello", "World"))
assert.Equal(t, "*Hello World*", MD2.Bold("Hello", "World"))
assert.Equal(t, "_Hello World_", MD2.Italic("Hello", "World"))
assert.Equal(t, "__Hello World__", MD2.Underline("Hello", "World"))
assert.Equal(t, "~Hello World~", MD2.Strike("Hello", "World"))
assert.Equal(t, "||Hello World||", MD2.Spoiler("Hello", "World"))
assert.Equal(t, "[Hello World](https://telegram.org)", MD2.Link("Hello World", "https://telegram.org"))
assert.Equal(t, "`Hello World`", MD2.Code("Hello World"))
assert.Equal(t, "```Hello World```", MD2.Pre("Hello World"))
assert.Equal(t, ">Hello World", MD2.Blockquote("Hello World"))
assert.Equal(t, "*Hello, World*", MD2.Sep(", ").Bold("Hello", "World"))
assert.Equal(t, "\\[\\*go\\_tg\\*\\]", MD2.Escape("[*go_tg*]"))
assert.Equal(t, "go\\.tg", MD2.Escape("go.tg"))
}