-
Notifications
You must be signed in to change notification settings - Fork 5
/
reverseV2_test.go
69 lines (59 loc) · 2.17 KB
/
reverseV2_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
package tg_md2html_test
import (
"testing"
"github.com/stretchr/testify/assert"
tg_md2html "github.com/PaulSonOfLars/gotg_md2html"
)
func TestReverseV2(t *testing.T) {
for _, test := range reverseTest {
t.Run(test, func(t *testing.T) {
out, err := tg_md2html.ReverseV2(tg_md2html.MD2HTMLV2(test), nil)
assert.NoError(t, err, "Error for:\n%s", test)
assert.Equal(t, tg_md2html.MD2HTMLV2(test), tg_md2html.MD2HTMLV2(out))
})
}
for _, test := range append(append(basicMD, basicMDv2...), advancedMD...) {
t.Run(test.in, func(t *testing.T) {
out, err := tg_md2html.ReverseV2(tg_md2html.MD2HTMLV2(test.in), nil)
assert.NoError(t, err, " Error for:\n%s", test)
assert.Equal(t, tg_md2html.MD2HTMLV2(test.in), tg_md2html.MD2HTMLV2(out))
})
}
for _, test := range []string{
"___________test_______", // uneven underlines
"|||||spoiler|||", // uneven spoilers
"||<spoiler>||", // spoilers, but with HTML bits inside
"![👍](tg://emoji?id=5368324170671202286)", // premium emoji
"> ", // empty quotes
"test\n>\ntest", // multiline quotes
"||||||||| test", // nested spoilers
} {
t.Run(test, func(t *testing.T) {
htmlv2 := tg_md2html.MD2HTMLV2(test)
out, err := tg_md2html.ReverseV2(htmlv2, nil)
assert.NoError(t, err, "Error for:\n%s", test)
assert.Equal(t, htmlv2, tg_md2html.MD2HTMLV2(out))
})
}
}
func TestReverseV2Buttons(t *testing.T) {
for _, x := range md2HTMLV2Buttons {
t.Run(x.in, func(t *testing.T) {
cv := tg_md2html.NewV2(map[string]string{
"url": "buttonurl:",
"text": "buttontext:",
})
// Button parsing is lossful; we apply opinionated changes to ensure stability. (eg, strip markdown from button names)
// So, we don't compare the reverse to the input.
// Instead, we ensure that the parsed input is equal to the parsed reverse.
txt, b := cv.MD2HTMLButtons(x.in)
assert.Equal(t, x.out, txt)
assert.ElementsMatch(t, x.btns, b)
out, err := cv.Reverse(txt, x.btns)
assert.NoError(t, err, "no error expected")
txt2, b2 := cv.MD2HTMLButtons(out)
assert.Equal(t, txt, txt2)
assert.ElementsMatch(t, b, b2)
})
}
}