forked from thatguystone/swan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle_test.go
95 lines (81 loc) · 1.88 KB
/
article_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
package swan
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
var (
contentDirs = []string{
"test_data/processors/comics/",
"test_data/processors/default/",
}
)
func TestProcessors(t *testing.T) {
t.Parallel()
hijiackHTTP()
for _, dir := range contentDirs {
filepath.Walk(dir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Fatalf("error while walking directory %s: %s",
dir,
err)
}
if info.IsDir() || !strings.HasSuffix(path, ".in") {
return nil
}
baseName := strings.Replace(path, ".in", "", -1)
htmlOut := fmt.Sprintf("%s.html.out", baseName)
textOut := fmt.Sprintf("%s.text.out", baseName)
in, err := ioutil.ReadFile(path)
if err != nil {
t.Fatalf("Failed to read input for %s: %s", baseName, err)
}
html, htmlErr := ioutil.ReadFile(htmlOut)
text, textErr := ioutil.ReadFile(textOut)
if htmlErr != nil && textErr != nil {
t.Fatalf("%s: \n"+
" htmlErr: %s\n"+
" textErr: %s",
baseName,
htmlErr,
textErr)
}
parts := bytes.SplitN(in, []byte("\n"), 2)
a, err := FromHTML(string(parts[0]), parts[1])
if err != nil {
t.Fatalf("%s: %s", baseName, err)
}
aHTML := ""
if a.TopNode != nil {
aHTML, _ = a.TopNode.Html()
aHTML = strings.TrimSpace(aHTML)
}
eHTML := strings.TrimSpace(string(html))
if htmlErr == nil && eHTML != aHTML {
t.Fatalf(
"%s: HTML does not match:\n"+
" Got: %s\n"+
" Expected: %s",
baseName,
aHTML,
eHTML)
}
eText := strings.TrimSpace(string(text))
if textErr == nil && eText != a.CleanedText {
t.Fatalf(
"%s: CleanedText does not match:\n"+
" Got: %s\n"+
" Expected: %s",
baseName,
a.CleanedText,
eText)
}
return nil
})
}
}