-
Notifications
You must be signed in to change notification settings - Fork 17
/
parser_test.go
89 lines (83 loc) · 1.65 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tbcload
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
)
const uriPath = "https://github.com/ActiveState/teapot/raw/master/lib/tbcload/tests/tbc10"
var fileNames = []string{
"aux1.tbc",
"break.tbc",
"break1.tbc",
"break2.tbc",
"catch.tbc",
"catch1.tbc",
"cont.tbc",
"cont1.tbc",
"expr.tbc",
"expr1.tbc",
"expr2.tbc",
"for.tbc",
"foreach.tbc",
"interp.tbc",
"override.tbc",
"proc.tbc",
"procbod1.tbc",
"procbod2.tbc",
"procbod3.tbc",
"procbreak1.tbc",
"proccatch1.tbc",
"proccatch2.tbc",
"proccontinue1.tbc",
"procepc1.tbc",
"procepc2.tbc",
"procshd1.tbc",
"procshd2.tbc",
"procshd3.tbc",
"procshd4.tbc",
"procshd5.tbc",
"procshd6.tbc",
"procshd7.tbc",
"procshd8.tbc",
"procvar1.tbc",
"procvar2.tbc",
"while.tbc",
}
func testURLTBC(t *testing.T, uriPath string, fileName string) {
r, err := http.Get(fmt.Sprintf("%s/%s", uriPath, fileName))
if err != nil {
t.Errorf("failed read uri:%s", fileName)
return
}
p := NewParser(r.Body, ioutil.Discard)
p.Detail = true
err = p.Parse()
if err != nil {
t.Errorf("failed parse uri:%s;err=%s", fileName, err)
}
r.Body.Close()
t.Logf("success uri:%s", fileName)
}
func testURLs(t *testing.T, uriPath string, fileNames []string) {
for _, s := range fileNames {
testURLTBC(t, uriPath, s)
}
}
func TestParser(t *testing.T) {
testURLs(t, uriPath, fileNames)
}
func TestSingleFile(t *testing.T) {
sFile := "1.tbc"
fs, err := os.Open(sFile)
if err != nil {
t.Error(err)
return
}
p := NewParser(fs, os.Stdout)
p.Detail = true
if err = p.Parse(); err != nil {
t.Error(err)
}
}