Skip to content

Commit

Permalink
Merge pull request #7 from multiformats/uvarint-tests
Browse files Browse the repository at this point in the history
tests for unbounded uvarint streams.
  • Loading branch information
Jakub Sztandera committed Aug 7, 2020
2 parents a3ded45 + bc41d4e commit 5d9803d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions varint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ func TestVarintSize(t *testing.T) {
}
}

func TestOverflow_9thSignalsMore(t *testing.T) {
buf := bytes.NewBuffer([]byte{
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0x80,
})

_, err := ReadUvarint(buf)
if err != ErrOverflow {
t.Fatalf("expected ErrOverflow, got: %s", err)
}
}

func TestOverflow_ReadBuffer(t *testing.T) {
buf := bytes.NewBuffer([]byte{
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
})

_, err := ReadUvarint(buf)
if err != ErrOverflow {
t.Fatalf("expected ErrOverflow, got: %s", err)
}
}

func TestOverflow(t *testing.T) {
i, n, err := FromUvarint(
[]byte{
Expand Down

0 comments on commit 5d9803d

Please sign in to comment.