-
Notifications
You must be signed in to change notification settings - Fork 11
/
tidy_test.go
75 lines (56 loc) · 1.4 KB
/
tidy_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
package tidy
import (
"strings"
"testing"
)
var corruptedHtml string = "<title id='bob' class='frank'>Hello, 世界</title><p>Foo!"
func Test_Tidy(t *testing.T) {
tdy := New()
defer tdy.Free()
output, _ := tdy.Tidy(corruptedHtml)
if !strings.HasPrefix(output, "<html>") {
t.Errorf("Unable to fix corrupted HTML")
}
}
func Test_AddXmlDecl(t *testing.T) {
tdy := New()
defer tdy.Free()
var output string
tdy.OutputXml(true)
tdy.AddXmlDecl(true)
output, _ = tdy.Tidy(corruptedHtml)
if !strings.HasPrefix(output, "<?xml") {
t.Errorf("XML declaration was not added")
}
tdy.AddXmlDecl(false)
output, _ = tdy.Tidy(corruptedHtml)
if strings.HasPrefix(output, "<?xml") {
t.Errorf("XML declaration must be omitted")
}
}
func Test_TidyMark(t *testing.T) {
tdy := New()
defer tdy.Free()
var output string
tdy.TidyMark(true)
output, _ = tdy.Tidy(corruptedHtml)
if !strings.Contains(output, "HTML Tidy for") {
t.Errorf("Tidy mark was not added")
}
tdy.TidyMark(false)
output, _ = tdy.Tidy(corruptedHtml)
if strings.Contains(output, "HTML Tidy for") {
t.Errorf("Tidy mark must be omitted")
}
}
func Test_Multibyte(t *testing.T) {
tdy := New()
defer tdy.Free()
var output string
tdy.InputEncoding(Utf8)
tdy.OutputEncoding(Utf8)
output, _ = tdy.Tidy(corruptedHtml)
if !strings.Contains(output, "世界") {
t.Errorf("The output is not in UTF-8 or unicode symbols were encoded")
}
}