-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_test.go
More file actions
65 lines (59 loc) · 1.71 KB
/
html_test.go
File metadata and controls
65 lines (59 loc) · 1.71 KB
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
package head
import (
"strings"
"testing"
"github.com/go-test/deep"
)
var htmlStringGeneral = `
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<base href="http://example.com/">
<meta charset="utf-8">
<link rel="rel1" href="http://example.com/rel1/1" type="text/html" title="title rel1 1">
<link rel="rel1" href="http://example.com/rel1/2" type="text/html" title="title rel1 2">
<link rel="rel2" href="http://example.com/rel2" type="text/html" title="title rel2">
<meta property="property1" content="property1">
<meta property="property2" content="property2">
<meta name="name1" content="name1">
<meta http-equiv="http-equiv1" content="http-equiv1">
<meta itemprop="itemprop1" content="itemprop1">
</head>
<body>
</body>
</html>
`
func TestParseHTML(t *testing.T) {
t.Run("T=general", func(t *testing.T) {
got, err := ParseHTML(strings.NewReader(htmlStringGeneral))
if err != nil {
t.Errorf("expected error to be nil in parsing HTML, got %s", err.Error())
return
}
expected := &Object{
Title: "title",
Base: "http://example.com/",
Charset: "utf-8",
Links: map[string][]*Link{
"rel1": {
&Link{HREF: "http://example.com/rel1/1", Type: "text/html", Title: "title rel1 1"},
&Link{HREF: "http://example.com/rel1/2", Type: "text/html", Title: "title rel1 2"},
},
"rel2": {
&Link{HREF: "http://example.com/rel2", Type: "text/html", Title: "title rel2"},
},
},
Metas: map[string]string{
"property1": "property1",
"property2": "property2",
"name1": "name1",
"http-equiv1": "http-equiv1",
"itemprop1": "itemprop1",
},
}
if diff := deep.Equal(expected, got); diff != nil {
t.Error(diff)
}
})
}