-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhtml_parser_test.go
75 lines (69 loc) · 1.56 KB
/
html_parser_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 golibxml
import "testing"
import "io/ioutil"
const TEST_HTML_FILE = "test/test.html"
const TEST_HTML_EXPECTED = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html></html>\n"
func TestParseHTMLDoc(t *testing.T) {
doc := ParseHTMLDoc("<html></html>", "UTF-8")
if doc == nil {
t.Fail()
}
defer doc.Free()
compareResult(t, doc.String(), TEST_HTML_EXPECTED)
}
/*
func TestParseHTMLDocLeak(t *testing.T) {
for i := 0; i < 100000; i++ {
TestParseHTMLDoc(t)
}
if getRSS() > 4000 {
t.Fatal("Memory leak")
}
}
*/
func TestParseHTMLFile(t *testing.T) {
doc := ParseHTMLFile(TEST_HTML_FILE, "UTF-8")
if doc == nil {
t.Fail()
}
defer doc.Free()
compareResult(t, doc.String(), TEST_HTML_EXPECTED)
}
/*
func TestParseHTMLFileLeak(t *testing.T) {
for i := 0; i < 100000; i++ {
TestParseHTMLFile(t)
}
if getRSS() > 4000 {
t.Fatal("Memory leak")
}
}
*/
func TestReadHTMLDoc(t *testing.T) {
doc := ReadHTMLDoc("<html></html>", "", "", 0)
if doc == nil {
t.Fail()
}
defer doc.Free()
compareResult(t, doc.String(), TEST_HTML_EXPECTED)
}
func TestReadHTMLFile(t *testing.T) {
doc := ReadHTMLFile(TEST_HTML_FILE, "UTF-8", 0)
if doc == nil {
t.Fail()
}
defer doc.Free()
compareResult(t, doc.String(), TEST_HTML_EXPECTED)
}
func TestReadHTMLMemory(t *testing.T) {
buf, err := ioutil.ReadFile(TEST_HTML_FILE)
if err != nil {
t.Fatal(err)
}
doc := ReadHTMLMemory(buf, "/", "UTF-8", 0)
if doc == nil {
t.Fail()
}
defer doc.Free()
compareResult(t, doc.String(), TEST_HTML_EXPECTED)
}