-
Notifications
You must be signed in to change notification settings - Fork 2
/
ensure_test.go
55 lines (49 loc) · 1.3 KB
/
ensure_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
package gobls
import (
"testing"
)
func ensureDone(tb testing.TB, s Scanner) {
tb.Helper()
// Scan and check results.
if got, want := s.Scan(), false; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Text(), ""; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Err(), error(nil); got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
// Do it again to ensure idempotent.
if got, want := s.Scan(), false; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Text(), ""; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Err(), error(nil); got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
}
func ensureScan(tb testing.TB, s Scanner, v string) {
tb.Helper()
if got, want := s.Scan(), true; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Text(), v; got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
if got, want := s.Err(), error(nil); got != want {
tb.Errorf("GOT: %#v; WANT: %#v", got, want)
}
}
func ensureSequence(t *testing.T, name string, s Scanner, seq []string) {
t.Helper()
t.Run(name, func(t *testing.T) {
t.Helper()
for _, want := range seq {
ensureScan(t, s, want)
}
ensureDone(t, s)
})
}