-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestsuite_test.go
62 lines (51 loc) · 1.35 KB
/
testsuite_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
package microformats_test
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
"reflect"
"testing"
"github.com/andyleap/microformats"
)
var parser = microformats.New()
func TestSuite(t *testing.T) {
passes := 0
count := 0
testsdir, _ := os.Open("tests")
suites, _ := testsdir.Readdir(0)
for _, suite := range suites {
if suite.IsDir() {
suitedir, _ := os.Open(path.Join("tests", suite.Name()))
suitedirs, _ := suitedir.Readdir(0)
for _, test := range suitedirs {
if test.IsDir() {
count = count + 1
if runTest(path.Join("tests", suite.Name(), test.Name())) {
fmt.Printf("PASS: %s/%s\n", suite.Name(), test.Name())
passes = passes + 1
} else {
fmt.Printf("FAIL: %s/%s\n", suite.Name(), test.Name())
t.Fail()
}
}
}
}
}
fmt.Printf("PASSING %d OF %d\n", passes, count)
}
func runTest(test string) bool {
input, _ := ioutil.ReadFile(path.Join(test, "input.html"))
URL, _ := url.Parse("http://tantek.com/")
data := parser.Parse(bytes.NewReader(input), URL)
expectedJson, _ := ioutil.ReadFile(path.Join(test, "output.json"))
expected := make(map[string]interface{})
json.Unmarshal(expectedJson, &expected)
outputJson, _ := json.Marshal(data)
output := make(map[string]interface{})
json.Unmarshal(outputJson, &output)
return reflect.DeepEqual(output, expected)
}