-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanners_test.go
73 lines (58 loc) · 1.19 KB
/
scanners_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
package readers
import (
"bytes"
"testing"
)
/* already declared in test_readers.go
var (
test_input = []string{
"one",
"two",
"three",
"four",
"five",
"six",
"seven"}
)
func validate(test *testing.T, in, out []string) {
if len(in) != len(out) {
test.Logf("output (%d) != input (%d)", len(out), len(in))
test.Fail()
}
for i := range in {
if in[i] != out[i] {
test.Logf("%d: output (%v) != input (%v)", i, out[i], in[i])
test.Fail()
}
}
}
*/
func TestScanArgs(test *testing.T) {
test_output := []string{}
scanner := ScanArgs(test_input)
for scanner.Scan() {
test_output = append(test_output, scanner.Text())
}
if scanner.Err() != nil {
test.Log("scanner error", scanner.Err())
test.Fail()
}
validate(test, test_input, test_output)
}
func TestScanReader(test *testing.T) {
test_output := []string{}
binput := bytes.NewBufferString("")
for _, l := range test_input {
binput.WriteString(l)
binput.WriteString("\n")
}
scanner := ScanReader(binput)
for scanner.Scan() {
test_output = append(test_output, scanner.Text())
}
if scanner.Err() != nil {
test.Log("scanner error", scanner.Err())
test.Fail()
}
validate(test, test_input, test_output)
}