-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscanner_test.go
75 lines (64 loc) · 1.49 KB
/
scanner_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
package eclint_test
import (
"bytes"
"fmt"
"testing"
"gitlab.com/greut/eclint"
)
func TestReadLines(t *testing.T) {
tests := []struct {
Name string
File []byte
LineFunc eclint.LineFunc
}{
{
Name: "Empty file",
File: []byte(""),
LineFunc: func(i int, line []byte, isEOF bool) error {
if i != 0 || len(line) > 0 {
return fmt.Errorf("more than one line found (%d), or non empty line %q", i, line)
}
return nil
},
}, {
Name: "crlf",
File: []byte("\r\n\r\n"),
LineFunc: func(i int, line []byte, isEOF bool) error {
if i > 1 || len(line) > 2 {
return fmt.Errorf("more than two lines found (%d), or non empty line %q", i, line)
}
return nil
},
}, {
Name: "cr",
File: []byte("\r\r"),
LineFunc: func(i int, line []byte, isEOF bool) error {
if i > 1 || len(line) > 2 {
return fmt.Errorf("more than two lines found (%d), or non empty line %q", i, line)
}
return nil
},
}, {
Name: "lf",
File: []byte("\n\n"),
LineFunc: func(i int, line []byte, isEOF bool) error {
if i > 1 || len(line) > 2 {
return fmt.Errorf("more than two lines found (%d), or non empty line %q", i, line)
}
return nil
},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
r := bytes.NewReader(tc.File)
errs := eclint.ReadLines(r, -1, tc.LineFunc)
if len(errs) > 0 {
t.Errorf("no errors were expected, got some. %s", errs[0])
return
}
})
}
}