-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileinput_test.go
More file actions
60 lines (55 loc) · 1.3 KB
/
fileinput_test.go
File metadata and controls
60 lines (55 loc) · 1.3 KB
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
package fileinput_test
import (
"io"
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/doloopwhile/go-fileinput"
)
func TestLines(t *testing.T) {
assert := assert.New(t)
data := map[string]string{
"a": "a01\na02\na03",
"b": "b01\nb02\nb03\n",
"c": "c01\nc02\nc03",
}
sc := &fileinput.Scanner{
Args: []string{"a", "b", "c"},
Open: func(name string) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader(data[name])), nil
},
}
lines := []string{}
for sc.Scan() {
line := sc.Text()
lines = append(lines, line)
// spot check progress fields
switch line {
case "a01":
assert.Equal(1, sc.LineNo())
assert.Equal(1, sc.FileLineNo())
assert.Equal(true, sc.IsFirstLine())
case "a03":
assert.Equal(3, sc.LineNo())
assert.Equal(3, sc.FileLineNo())
assert.Equal(false, sc.IsFirstLine())
case "c01":
assert.Equal(7, sc.LineNo())
assert.Equal(1, sc.FileLineNo())
assert.Equal(true, sc.IsFirstLine())
case "c02":
assert.Equal(8, sc.LineNo())
assert.Equal(2, sc.FileLineNo())
assert.Equal(false, sc.IsFirstLine())
}
}
assert.NoError(sc.Err())
expected := []string{
"a01", "a02", "a03",
"b01", "b02", "b03",
"c01", "c02", "c03",
}
assert.Equal(expected, lines)
assert.Equal(len(expected), sc.LineNo())
}