-
Notifications
You must be signed in to change notification settings - Fork 0
/
advancer_test.go
45 lines (37 loc) · 931 Bytes
/
advancer_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
package midec_test
import (
"bytes"
"fmt"
"testing"
"github.com/sapphi-red/midec"
)
func Test_ReadAdvancer_Advance(t *testing.T) {
t.Parallel()
runAdvance := func(byteLen, advanceLen int) error {
empty := make([]byte, byteLen)
advancer := midec.NewReadAdvancer(bytes.NewReader(empty))
return advancer.Advance(uint(advanceLen))
}
testcases := []struct {
byteLen int
advanceLen int
expectedHasError bool
}{
{0, 1, true},
{1, 1, false},
{1, 256 * 3 + 1, true},
{256 * 3 + 1, 256 * 3 + 1, false},
{256 * 3 + 1, 256 * 3 + 2, true},
}
for _, tc := range testcases {
tc := tc
name := fmt.Sprintf("%d %d", tc.byteLen, tc.advanceLen)
t.Run(name, func(t *testing.T) {
t.Parallel()
actualErr := runAdvance(tc.byteLen, tc.advanceLen)
if tc.expectedHasError != (actualErr != nil) {
t.Errorf("Error = %v; want HasError = %t", actualErr, tc.expectedHasError)
}
})
}
}