forked from Morganamilo/go-srcinfo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printsrcinfo_test.go
57 lines (47 loc) · 1.17 KB
/
printsrcinfo_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
package srcinfo
import (
"os"
"path/filepath"
"strings"
"testing"
)
func srcinfosEqual(t *testing.T, name, data, file string) {
dataLines := strings.Split(data, "\n")
fileLines := strings.Split(file, "\n")
data:
for line, dataLine := range dataLines {
trimmed := strings.TrimSpace(dataLine)
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
continue
}
for _, fileLine := range fileLines {
if dataLine == fileLine {
continue data
}
}
t.Errorf("%s Line %d \"%s\" can not be found in source file. %v", name, line, dataLine, fileLines)
}
}
func TestPrintSrcinfo(t *testing.T) {
for _, name := range goodSrcinfos {
path := filepath.Join(goodSrcinfoDir, name)
srcinfo, err := ParseFile(path)
if err != nil {
t.Errorf("Error parsing %s: %s", name, err)
continue
}
file, err := os.ReadFile(path)
if err != nil {
t.Errorf("Unable to read file: %s: %s", path, err.Error())
continue
}
srcinfosEqual(t, name, srcinfo.String(), string(file))
}
}
func TestPrintSrcinfoEmpty(t *testing.T) {
srcinfo := &Srcinfo{}
str := srcinfo.String()
if str != "" {
t.Errorf("Empty srcinfo should generate empty string but gave: %s", str)
}
}