forked from Morganamilo/go-srcinfo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
81 lines (66 loc) · 1.66 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
package srcinfo
import (
"testing"
)
func TestCurrentPackage(t *testing.T) {
srcinfo := &Srcinfo{}
splitpkg := &Package{}
psr := &parser{srcinfo, make(map[string]struct{})}
_, err := psr.currentPackage()
if err == nil {
t.Errorf("currentPackage should because of no header but didn't")
}
psr.srcinfo.Pkgbase = "foo"
pkg, err := psr.currentPackage()
if err != nil {
t.Error(err)
} else if pkg != &srcinfo.Package {
t.Errorf("currentPackage does not return srcinfo.Package")
}
srcinfo.Packages = append(srcinfo.Packages, *splitpkg)
pkg, err = psr.currentPackage()
if err != nil {
t.Error(err)
} else if pkg != &srcinfo.Packages[0] {
t.Errorf("currentPackage does not return srcinfo.Packages[0]")
}
}
func TestSplitPair(t *testing.T) {
const keyGood string = "a"
const valueGood string = "b"
inputGood := [...]string{
"a = b",
" a = b ",
"a=b",
"\ta\t=\tb\t",
}
inputBad := [...]string{
"",
"=",
//"a=",
"=b",
}
for _, str := range inputGood {
key, value, err := splitPair(str)
if err != nil {
t.Errorf("failed to split line \"%s\": %s", str, err)
}
if key != keyGood || value != valueGood {
t.Errorf("failed to split line \"%s\": expected key=%s value=%s, got key=%s value=%s", str, keyGood, valueGood, key, value)
}
}
for _, str := range inputBad {
_, _, err := splitPair(str)
if err == nil {
t.Errorf("Split line should have errored but didn't: %s", str)
}
}
}
func TestSetField(t *testing.T) {
srcinfo := &Srcinfo{}
psr := &parser{srcinfo, make(map[string]struct{})}
err := psr.setField("install", "foo")
if err == nil {
t.Errorf("setField should have errored due to no header but did not")
}
}