-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathutils_test.go
120 lines (107 loc) · 4.57 KB
/
utils_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package gohtml
import (
"bytes"
"strings"
"testing"
)
func TestWriteLineFeed(t *testing.T) {
bf := &formattedBuffer{
buffer: &bytes.Buffer{},
}
bf.writeToken("test \n ", formatterTokenType_Text)
bf.writeLineFeed()
actual := bf.buffer.String()
expected := "test \n\n"
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}
func TestWriteIndent(t *testing.T) {
bf := &formattedBuffer{
buffer: &bytes.Buffer{},
indentString: " ",
indentLevel: 3,
}
bf.writeIndent()
actual := bf.buffer.String()
expected := " "
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}
func TestWriteTokenSpacing(t *testing.T) {
bf := &formattedBuffer{
buffer: &bytes.Buffer{},
}
bf.writeToken("text1", formatterTokenType_Text)
bf.writeToken("text2", formatterTokenType_Text)
bf.writeToken("text3", formatterTokenType_Text)
bf.writeLineFeed()
bf.writeToken("text1", formatterTokenType_Text)
bf.writeToken("<tag1>", formatterTokenType_Tag)
bf.writeToken("<tag2>", formatterTokenType_Tag)
bf.writeToken("text2", formatterTokenType_Text)
bf.writeLineFeed()
bf.writeToken("<tag1>", formatterTokenType_Tag)
bf.writeToken("text1", formatterTokenType_Text)
bf.writeToken("text2", formatterTokenType_Text)
bf.writeToken("<tag2>", formatterTokenType_Tag)
bf.writeLineFeed()
bf.writeToken("<tag1>", formatterTokenType_Tag)
bf.writeToken("<tag2>", formatterTokenType_Tag)
bf.writeToken("<tag3>", formatterTokenType_Tag)
actual := bf.buffer.String()
expected := "text1 text2 text3\n" +
"text1<tag1><tag2>text2\n" +
"<tag1>text1 text2<tag2>\n" +
"<tag1><tag2><tag3>"
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}
func TestWriteTokenWrapping(t *testing.T) {
bf := &formattedBuffer{
buffer: &bytes.Buffer{},
lineWrapColumn: 80,
}
for _, word := range strings.Split("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", " ") {
bf.writeToken(word, formatterTokenType_Text)
}
actual := bf.buffer.String()
expected := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\n" +
"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\n" +
"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n" +
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\n" +
"fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n" +
"culpa qui officia deserunt mollit anim id est laborum."
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}
func TestWriteTokenWrappingWithSpillover(t *testing.T) {
bf := &formattedBuffer{
buffer: &bytes.Buffer{},
lineWrapColumn: 80,
lineWrapMaxSpillover: 5,
}
for _, word := range strings.Split("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", " ") {
bf.writeToken(word, formatterTokenType_Text)
}
actual := bf.buffer.String()
expected := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\n" +
"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud\n" +
"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute\n" +
"irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\n" +
"nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa\n" +
"qui officia deserunt mollit anim id est laborum."
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}
func TestUnifyLineFeed(t *testing.T) {
actual := unifyLineFeed("\r\n\n\r")
expected := "\n\n\n"
if actual != expected {
t.Errorf("Invalid result. [expected: %s][actual: %s]", expected, actual)
}
}