Skip to content

Commit 5d9803d

Browse files
authored
Merge pull request #7 from multiformats/uvarint-tests
tests for unbounded uvarint streams.
2 parents a3ded45 + bc41d4e commit 5d9803d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

varint_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@ func TestVarintSize(t *testing.T) {
3434
}
3535
}
3636

37+
func TestOverflow_9thSignalsMore(t *testing.T) {
38+
buf := bytes.NewBuffer([]byte{
39+
0xff, 0xff, 0xff, 0xff,
40+
0xff, 0xff, 0xff, 0xff,
41+
0x80,
42+
})
43+
44+
_, err := ReadUvarint(buf)
45+
if err != ErrOverflow {
46+
t.Fatalf("expected ErrOverflow, got: %s", err)
47+
}
48+
}
49+
50+
func TestOverflow_ReadBuffer(t *testing.T) {
51+
buf := bytes.NewBuffer([]byte{
52+
0xff, 0xff, 0xff, 0xff,
53+
0xff, 0xff, 0xff, 0xff,
54+
0xff, 0xff, 0xff, 0xff,
55+
0xff, 0xff, 0xff, 0xff,
56+
0xff, 0xff, 0xff, 0xff,
57+
0xff, 0xff, 0xff, 0xff,
58+
})
59+
60+
_, err := ReadUvarint(buf)
61+
if err != ErrOverflow {
62+
t.Fatalf("expected ErrOverflow, got: %s", err)
63+
}
64+
}
65+
3766
func TestOverflow(t *testing.T) {
3867
i, n, err := FromUvarint(
3968
[]byte{

0 commit comments

Comments
 (0)