forked from liuzl/et
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
46 lines (42 loc) · 984 Bytes
/
parse_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
package et
import (
"encoding/json"
"io/ioutil"
"testing"
"crawler.club/dl"
"zliu.org/goutil"
)
var tests = [][]string{
//[]string{"article.json", "http://www.newsmth.net/nForum/article/RealEstate/7124059"},
//[]string{"section.json", "http://www.newsmth.net/nForum/section/1"},
{"board.json", "http://www.newsmth.net/nForum/board/Universal"},
}
func TestParse(t *testing.T) {
for _, test := range tests {
b, err := ioutil.ReadFile(test[0])
if err != nil {
t.Fatal(err)
}
p := new(Parser)
if err = json.Unmarshal(b, p); err != nil {
t.Fatal(err)
}
url := test[1]
resp := dl.DownloadUrl(url)
if resp.Error != nil {
t.Fatal(resp.Error)
}
urls, items, err := p.Parse(resp.Text, url)
if err != nil {
t.Fatal(err)
}
if b, err = goutil.JSONMarshalIndent(urls, "", " "); err != nil {
t.Fatal(err)
}
t.Log(string(b))
if b, err = goutil.JSONMarshalIndent(items, "", " "); err != nil {
t.Fatal(err)
}
t.Log(string(b))
}
}