-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_test.go
63 lines (55 loc) · 1.88 KB
/
writer_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
package ftml
import (
"bytes"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSimpleParagraph(t *testing.T) {
res := "<p>This is a test.</p>\n"
buf := &bytes.Buffer{}
if assert.NoError(t, Write(buf, doc(p__("This is a test.")))) {
assert.Equal(t, res, buf.String())
}
}
func TestParagraphWithStyles(t *testing.T) {
res := `<p>This is <i>a little more complex</i> test.</p>
`
buf := &bytes.Buffer{}
if assert.NoError(t, Write(buf, doc(p_(span("This is "), i__("a little more complex"), span(" test."))))) {
assert.Equal(t, res, buf.String())
}
}
func TestSimpleStyles(t *testing.T) {
tests := map[string][]Span{
`This is a test.`: {span("This is a test.")},
`This is a <b>test</b>.`: {span("This is a "), b__("test"), span(".")},
`This is a <b> test </b>.`: {span("This is a "), b__(" test "), span(".")},
`This is a <b><i>second</i> test</b>.`: {span("This is a "), b_(i__("second"), span(" test")), span(".")},
}
for str, spans := range tests {
buf := &strings.Builder{}
dbg := &strings.Builder{}
mock := &output{Writer: buf, MaxWidth: 1000}
for idx, x := range spans {
assert.NoError(t, mock.writeSpan(x, 0, idx == 0, idx == len(spans)-1))
dbg.WriteString(x.String())
}
assert.Equalf(t, str, buf.String(), "written FTML not corrent for %s", dbg.String())
}
}
func TestWriteSpaces(t *testing.T) {
tests := map[string][]Span{
"<p> This is a test.</p>\n": {span(" This is a test.")},
"<p>This is a test. </p>\n": {span("This is a test. ")},
"<p>A   B</p>\n": {span("A B")},
"<p>\n A<br />\n  B\n</p>\n": {span("A\n B")},
"<p>\n A <br />\n B\n</p>\n": {span("A \nB")},
}
for str, spans := range tests {
buf := &bytes.Buffer{}
if assert.NoError(t, Write(buf, doc(p_(spans...)))) {
assert.Equal(t, str, buf.String())
}
}
}