-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_test.go
74 lines (58 loc) · 1.8 KB
/
setup_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
package textplain_test
import (
"reflect"
"testing"
"github.com/mailproto/textplain"
"github.com/stretchr/testify/assert"
)
func runTestCases(t *testing.T, testCases []testCase) {
for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) {
runTestCase(tt, tc)
})
}
}
func runTestCase(t *testing.T, tc testCase, converters ...textplain.Converter) {
if len(converters) == 0 {
converters = []textplain.Converter{textplain.NewRegexpConverter(), textplain.NewTreeConverter()}
}
for _, converter := range converters {
t.Run(reflect.TypeOf(converter).Elem().Name(), func(tt *testing.T) {
result, err := converter.Convert(tc.body, textplain.DefaultLineLength)
assert.Nil(tt, err)
assert.Equal(tt, tc.expect, result)
})
}
}
const html = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
.button { color: red; }
</style>
</head>
<body>
<!-- start email -->
<h6>Small header</h6>
<p style="font-weight: bold; color: red;" class="button">Hello></p>
<p>
<a href="http://example.com"><img alt="An Example" src="https://example.com/image.jpg/></a><br/>
<a href="https://example.com/fancy" class="fancy">Fancy text</a>
</p>
<ol>
<li>item one</li>
<li>item two</li>
<li>item three</li>
</ol>
<img src="https://example.com/footer-animation.gif" /></body></html>`
func BenchmarkRegexp(b *testing.B) {
converter := textplain.NewRegexpConverter()
for i := 0; i < b.N; i++ {
_, _ = converter.Convert(html, textplain.DefaultLineLength)
}
}
func BenchmarkTree(b *testing.B) {
converter := textplain.NewTreeConverter()
for i := 0; i < b.N; i++ {
_, _ = converter.Convert(html, textplain.DefaultLineLength)
}
}