-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_test.go
208 lines (197 loc) · 6.54 KB
/
html_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package runic
import "testing"
type htmlTest struct {
name string
input string
expectedHtml string
}
var htmlTests = []htmlTest{
{
"empty file",
"",
"",
},
{
"paragraph",
"The quick brown fox jumps over the lazy dog",
"<p>The quick brown fox jumps over the lazy dog</p>",
},
{
"heading one",
". This is a level one heading",
"<h1>This is a level one heading</h1>",
},
{
"heading two",
": This is a level two heading",
"<h2>This is a level two heading</h2>",
},
{
"heading three",
":. This is a level three heading",
"<h3>This is a level three heading</h3>",
},
{
"heading four",
":: This is a level four heading",
"<h4>This is a level four heading</h4>",
},
{
"heading five",
"::. This is a level five heading",
"<h5>This is a level five heading</h5>",
},
{
"heading six",
"::: This is a level six heading",
"<h6>This is a level six heading</h6>",
},
{
"rich text",
"italic[quick]",
"<p><em>quick</em></p>",
},
{
"nested rich text",
"The quick bold[brown fox italic[jumps] over the] lazy dog",
"<p>The quick <b>brown fox <em>jumps</em> over the</b> lazy dog</p>",
},
{
"list",
"- Item one\n- Item two\n- Item three",
"<ul><li>Item one</li><li>Item two</li><li>Item three</li></ul>",
},
{
"list string literal",
`
- Item one
- Item two
`,
"<ul><li>Item one</li><li>Item two</li></ul>",
},
{
"list string literal v2",
`
- Item one
- Item two
`,
"<ul><li>Item one</li><ul><li>Item two</li></ul></ul>",
},
{
"list with indents v3",
`
- Item one
- Item two
- Item three
- Item four
- Item five
`,
"<ul><li>Item one</li><ul><li>Item two</li><ul><li>Item three</li></ul><li>Item four</li></ul><li>Item five</li></ul>",
},
}
func TestHtml(t *testing.T) {
for _, test := range htmlTests {
testParser := New()
htmlString := testParser.Html(test.input)
if htmlString != test.expectedHtml {
t.Errorf("%s ERROR\nexpected: %s\nreceived: %s", test.name, test.expectedHtml, htmlString)
continue
}
t.Log(test.name, "OK")
}
}
type highlightTextTest struct {
name string
input string
expectedHighlightText string
}
var highlightTextTests = []highlightTextTest{
{
"empty file",
"",
"",
},
{
"paragraph",
"The quick brown fox jumps over the lazy dog",
`<span class="runic__text">The quick brown fox jumps over the lazy dog</span>`,
},
{
"paragraph with one leading space",
" The quick brown fox jumps over the lazy dog",
`<span class="runic__text"> The quick brown fox jumps over the lazy dog</span>`,
},
{
"paragraph with multiple leading space",
" The quick brown fox jumps over the lazy dog",
`<span class="runic__text"> The quick brown fox jumps over the lazy dog</span>`,
},
{
"paragraph with one trailing space",
"The quick brown fox jumps over the lazy dog ",
`<span class="runic__text">The quick brown fox jumps over the lazy dog </span>`,
},
{
"paragraph with multple trailing space",
"The quick brown fox jumps over the lazy dog ",
`<span class="runic__text">The quick brown fox jumps over the lazy dog </span>`,
},
{
"paragraph with multiple inner whitespace",
"The quick brown fox jumps over the lazy dog",
`<span class="runic__text">The quick brown fox jumps over the lazy dog</span>`,
},
{
"paragraph with leading, trailing, and multiple inner whitespace",
" The quick brown fox jumps over the lazy dog ",
`<span class="runic__text"> The quick brown fox jumps over the lazy dog </span>`,
},
{
"heading one",
". This is a level one heading",
`<span class="runic__heading">. </span><span class="runic__text">This is a level one heading</span>`,
},
{
"rich text",
"The quick bold[brown fox jumps over the] lazy dog",
`<span class="runic__text">The quick </span><span class="runic__tag">bold</span><span class="runic__osq">[</span><span class="runic__text">brown fox jumps over the</span><span class="runic__csq">] </span><span class="runic__text">lazy dog</span>`,
},
{
"paragraph with surrounding newlines",
`
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
`,
`<span class="runic__text"><br> The quick brown fox jumps over the lazy dog<br><br> </span> <span class="runic__text">The quick brown fox jumps over the lazy dog<br> </span>`,
},
{
"lists",
`
- List item one
- List item two
- List item three
- List item four
- List item five
`,
`<span class="runic__bulletpoint"><br> - </span><span class="runic__text">List item one<br> </span><span class="runic__bulletpoint">- </span><span class="runic__text">List item two<br> </span><span class="runic__bulletpoint">- </span><span class="runic__text">List item three<br> </span><span class="runic__bulletpoint">- </span><span class="runic__text">List item four<br> </span><span class="runic__bulletpoint">- </span><span class="runic__text">List item five<br> </span> `,
},
{
"heading with paragraph underneath and surround whitespace",
`
. This is a level one heading
The quick brown fox jumps over the lazy dog
`,
`<span class="runic__heading"><br> . </span><span class="runic__text">This is a level one heading<br><br><br> </span> <span class="runic__text">The quick brown fox jumps over the lazy dog<br><br> </span> `,
},
}
func TestHighlightText(t *testing.T) {
for _, test := range highlightTextTests {
testParser := New()
highlightText := testParser.HighlightText(test.input)
if highlightText != test.expectedHighlightText {
t.Errorf("%s ERROR\nexpected: %s\nreceived: %s", test.name, test.expectedHighlightText, highlightText)
continue
}
t.Log(test.name, "OK")
}
}