-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner_test.go
55 lines (49 loc) · 956 Bytes
/
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
package goetf
import (
"bytes"
"io"
"testing"
)
func TestScanner(t *testing.T) {
b := []byte{131, 98, 0, 0, 1, 0}
scan := newScanner(bytes.NewReader(b))
{
p, err := scan.readByte()
if err != nil {
t.Fatal(err)
}
want := byte(131)
got := p
if got != want {
t.Errorf("error matching version flag: want = %v got = %v", want, got)
}
}
{
p, err := scan.readByte()
if err != nil {
t.Fatal(err)
}
want := byte(98)
got := p
if got != want {
t.Errorf("error matching type tag: want = %v got = %v", want, got)
}
}
{
_, b, err := scan.readN(4)
if err != nil {
t.Fatal(err)
}
want := []byte{0, 0, 1, 0}
got := b
if !bytes.Equal(want, got) {
t.Errorf("error matching sequence of bytes: want = %v got = %v", want, got)
}
}
{
_, _, err := scan.readN(0)
if err != io.EOF {
t.Errorf("error should be EOF, but got: %v", err)
}
}
}